Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 removes 4 letter words
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
aliveiswell




PostPosted: 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..."
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Mon Jan 12, 2004 6:00 pm   Post subject: (No subject)

cool idea, kinda pointless Razz interesting though Very Happy
Tony




PostPosted: Mon Jan 12, 2004 6:18 pm   Post subject: (No 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
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
shorthair




PostPosted: Fri Jan 23, 2004 10:21 am   Post subject: (No 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
Tony




PostPosted: Fri Jan 23, 2004 3:07 pm   Post subject: (No 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
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Maverick




PostPosted: Fri Jan 23, 2004 3:09 pm   Post subject: (No subject)

Y35 7H47 15 4 G00D 1D3A!
Andy




PostPosted: Fri Jan 23, 2004 5:24 pm   Post subject: (No subject)

u should've used index
sport




PostPosted: Fri Jan 23, 2004 7:12 pm   Post subject: (No 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
sport




PostPosted: Fri Jan 23, 2004 7:13 pm   Post subject: (No subject)

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




PostPosted: Mon Jan 26, 2004 10:51 am   Post subject: (No subject)

You could have just concatenated the different parts together at each new space, and not used an array.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 10 Posts ]
Jump to:   


Style:  
Search: