Computer Science Canada

removes 4 letter words

Author:  aliveiswell [ Mon Jan 12, 2004 5:45 pm ]
Post subject:  removes 4 letter words

this was the final test for some of the people in my class. it's pretty simple but im proud of it. it removes all 4 letter words from a sentence.

code:

var sentence : string

put "This program will remove all 4 letter words from a sentence."

loop
    put ""
    put "Please enter your sentence:"
    get sentence : *

    if length (sentence) > 80 then
        put "That sentence is too long, please type another sentence."
    else
        if sentence = "exit" then
            exit
        end if

        sentence := " " + sentence + " "
        put sentence

        var words : array 1 .. length (sentence) of string
        for counter : 1 .. length (sentence)
            words (counter) := sentence (counter)
        end for

        for counter : 2 .. length (sentence)
            if counter = 2 and sentence (counter) = " " then
            elsif counter = 3 and sentence (counter) = " " then
            elsif counter = 4 and sentence (counter) = " " then
            elsif counter = 5 and sentence (counter) = " " then
            elsif sentence (counter) = " " and sentence (counter - 5) = " " and sentence (counter - 4) not= " " and sentence (counter - 3) not= " " and sentence (counter - 2) not= " " and
                    sentence (counter - 1) not= " " then
                words (counter - 4) := "*"
                words (counter - 3) := "*"
                words (counter - 2) := "*"
                words (counter - 1) := "*"
            end if
        end for
        for counter : 1 .. length (sentence)
            put words (counter) ..
        end for
    end if
end loop
put "You have exited..."

Author:  Cervantes [ Mon Jan 12, 2004 6:00 pm ]
Post subject: 

cool idea, kinda pointless Razz interesting though Very Happy

Author:  Tony [ Mon Jan 12, 2004 6:18 pm ]
Post subject: 

i remember doing something like that a long while back... I think the story behind the program was to sensor a certain 4 letter word, but since it can easily be modified, they desided to just sensor all 4 letter words Laughing Doesn't really solve the problem though Laughing

Author:  shorthair [ Fri Jan 23, 2004 10:21 am ]
Post subject: 

Ummmm your proram is good at what it does , Very Happy , BUt you could probably mod that to censor out an array of words , so that it could actually be used for censor ship , but then you run into words spelt in spaces , G A * , and not even compsci has been able to * that out yet, id like to see a good censorship APP , it would actually be quite useful to me , as i do a bit of editing online

Author:  Tony [ Fri Jan 23, 2004 3:07 pm ]
Post subject: 

well as long as an app is sensoring, there will always be a way around it Confused

5uch 45 1337 5p34k, sensor that Laughing

heh, the only way I suppose would be to sensor everything that is not part of the dictionary of allowed words Shocked

Author:  Maverick [ Fri Jan 23, 2004 3:09 pm ]
Post subject: 

Y35 7H47 15 4 G00D 1D3A!

Author:  Andy [ Fri Jan 23, 2004 5:24 pm ]
Post subject: 

u should've used index

Author:  sport [ Fri Jan 23, 2004 7:12 pm ]
Post subject: 

If getting the sentence from a file you can use length command.
code:

var fileno:int
var filename:string:="NAME"
var word:string
loop
get :fileno,word
if length(word) not =4 then
esle
put word
end if
end for

Author:  sport [ Fri Jan 23, 2004 7:13 pm ]
Post subject: 

You will need a file called NAME in order for the program to work.

Author:  jonos [ Mon Jan 26, 2004 10:51 am ]
Post subject: 

You could have just concatenated the different parts together at each new space, and not used an array.


: