CCC 1998 Stage1: Problem A: Censor
Author |
Message |
Tony
|
Posted: Mon Jan 06, 2003 6:24 pm Post subject: CCC 1998 Stage1: Problem A: Censor |
|
|
Input file: censor.in
Output file: censor.out
The Society for the Prevention of Profanity on the Internet has observed a growing number of chat lines on the World-Wide Web. A chat line allows a Web user to type lines of text which are transmitted to all other users. The Society is concerned about the number of four-letter words being transmitted by these chat lines and has proposed the mandatory use of software to remove all four-letter words from every transmission. Your job is to write the software to do this removal.
The input to your program consists of an integer, n, on a line by itself, followed by n lines of text. Each line of text contains words separated by spaces. Each word consists of letters of the alphabet and exactly one space separates adjacent words. Lines do not exceed 80 characters in length.
The output from your program should consists of the n lines of text, with each four-letter word replaced by four asterisks. The lines should be separated by one blank line.
--------------------------------------------------------------------------------
Sample Input
2
The quick brown fox jumps over the lazy dog
Now is the time for all good people to come to the aid of the party
--------------------------------------------------------------------------------
Sample Output
The quick brown fox jumps **** the **** dog
Now is the **** for all **** people to **** to the aid of the party
|
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
Sponsor Sponsor
|
|
|
Tony
|
Posted: Tue Jan 07, 2003 2:50 am Post subject: (No subject) |
|
|
This problem is quite simple and straight forward... the only thing wrong with it, is that you can't take input 1 word at the time, you HAVE to take input as a whole line
get : fileNum, line:*
unless you find another way to keep track of when line ends (i actually know a way).
anyway, here's the solution in attached file. Its commented and as always you need to create a data.in file and put sample input data in there for program to work.
Description: |
|
Download |
Filename: |
1998 s1 p1.t |
Filesize: |
1 KB |
Downloaded: |
850 Time(s) |
|
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
JSBN
|
Posted: Fri Jan 31, 2003 8:57 am Post subject: Very Easy |
|
|
I found this problem quite easy in fact. Here's my answer to it
code: | var s : string
loop
get s
if length (s) = 4 then
put "**** " ..
else
put s, " " ..
end if
end loop
|
It's a nice short program that works. Well actually there is one obvious bug, but i wont tell you what it is.... o_O
This works beacuse if you enter a space into a get command, it will put the word after the space into the next get. Thus, because i have looped the program AND because i only have the one get command, this program works.
Tony, feel free to comment.
|
|
|
|
|
|
Tony
|
|
|
|
|
DarkHelmet
|
Posted: Sat Feb 08, 2003 11:45 am Post subject: (No subject) |
|
|
The following text works for this case, though it might not be the most efficient ever. strtext is the text input, and strnewtext is the text output.
intlength := length (strtext)
intcounter := 0
strnewtext := ""
loop
strword := ""
loop
intcounter := intcounter + 1
strletter := strtext (intcounter .. intcounter)
if strletter not= " " then
strword := strword + strletter
else
intlength2 := length (strword)
if intlength2 not= 4 then
strnewtext := strnewtext + strword + " "
else
strnewtext := strnewtext + "**** "
end if
exit
end if
if intcounter = intlength then
intlength2 := length (strword)
if intlength2 not= 4 then
strnewtext := strnewtext + strword
else
strnewtext := strnewtext + "****"
end if
exit
end if
end loop
exit when intcounter = intlength
end loop
put strnewtext
|
|
|
|
|
|
Tony
|
Posted: Sat Feb 08, 2003 2:08 pm Post subject: (No subject) |
|
|
thats what I was talking about - extracting individual words after you read the whole line.
Note: if you want to get individual character from a string, you can just use stringname(index), not stringname(index..index). Doesn't make the difference really, but its less typing and the program actually runs faster because otherwise you make it run through a loop
|
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
atmosphere
|
Posted: Thu Feb 13, 2003 3:56 pm Post subject: (No subject) |
|
|
i got something like this ,
var word : string
var input, output : int
open : input, "censor.in", get
open : output, "censor.out", put
loop
exit when eof (input)
get : input, word : *
var finalword : string := ""
var narr : array 1 .. length (word) of string
var b, y, z : int := 1
for x : 1 .. length (word)
if word (x) = chr (32) then
narr (z) := word (y .. x - 1)
z += 1
y := x + 1
end if
if x = length (word) then
narr (z) := word (y .. x)
end if
end for
for a : 1 .. z
if length (narr (a)) = 4 then
narr (a) := "****"
end if
finalword := finalword + " " + narr (a)
end for
put : output, finalword
end loop
close : output
close : input
im still kinda new to a few things, i just learned how to write/read to files from one of your tutorials(i slept through gr. 11 comp science) and im gonna try my luck at the ccc at the junior level just need some more practice
|
|
|
|
|
|
Tony
|
Posted: Thu Feb 13, 2003 4:23 pm Post subject: (No subject) |
|
|
you can have a max of 1 computer science credit at the time of writing to be eligible for stage 1. If you're in grade 11 comp sci at the moment of writing then you're ok. Though if you already have 10th and 11th credit, then you got to write Senior. Just clearing something things out.
Good luck on CCC 8)
|
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
Sponsor Sponsor
|
|
|
atmosphere
|
Posted: Fri Feb 14, 2003 2:28 pm Post subject: (No subject) |
|
|
man my comp teacher this year told us that the gr. 10 didnt really count as the credit, i think she wrote a letter, but i guess u prolly kno more of what ur saying. and yea i did take the one last year and the one this year cause i think it was a prerequisite for it
and gl to u too
|
|
|
|
|
|
|
|