1998 Canadian Computing Competition, Stage 1

Problem A: Censor

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.

Input

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.

Output

The output from your program should consist 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

All Submissions
Best Solutions


Point Value: 5
Time Limit: 2.00s
Memory Limit: 16M
Added: Oct 01, 2008

Problem Types: [Show]

Languages Allowed:
C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3

Comments (Search)

My program worked on my IDE but the Judge won't accept it. It simply gives me a

Note: ccc98s1.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

What does that mean?

That is not the issue, that is just warnings from the complier, but when give you any errors, the real error is from java.util.NoSuchElement Exception


Think carefully about the order in which you're incrementing and censoring.

How can I determine that a line is over?

The sample case worked with my code, but for the actual test case, I am getting all of the lines with just one getline.

Getline reads until the newline character, so it will automatically only read one line. You are actually reading line by line, its just that the judge clips output so you can't see all of your output.

As I am striving to improve my code performances (at least with problems this east), seeing that a huge number of problems has basically 0 running times makes me either feel rather frustrated or wish that is due to some bug: can someone from the staff confirm about it?

Everyone who has those runtimes have written the code in either c++ or pascal. Both languages are much faster than python. Learn to ignore what the best solutions part says and focus on your own code. As long as you get it right you're fine.

And thanks for your kind words too, fifiman; a more thorough answer to how I manage my challenges here on wcipeg is right below Alex's comment :).

Certain languages (namely C, C++, and Pascal) are inherently very fast - much faster than Python, Ruby, Java, and the like. There is nothing you can do about this. Most problems are built so that all languages can pass provided that the asymptotic running time is correct. There are really no merits to improving your solution beyond getting AC (unless you want to practice constant optimization, which is a different issue). Your time is better spent on trying to work through harder problems.

As a side note, you might've noticed that even recent C/C++/Pascal submissions cannot get exactly 0.000s like many best submissions you've seen. This is because those were submitted back when the judge had a different grading system (and possibly even hardware?), so the execution times may not have been as accurate.

Ops, I expected some kind of notification and missed this one: you may be right that my time is best spent elsewhere, though seeing that my slick algos are performing slower than some simple brute force may be frustrating.

Even so, I am here also to try and improve my performances, not just getting the right answer (which often is way too plain to me), so I'll try not to focus too much on my own reported times and a tad more on other users best practices and interesting code.

Btw, I sincerely doubt that C or the poor Pascal can really be HUNDREDS of time faster than my good old snake.

Do i have to take care of punctuation or symbols or numbers (such as 1234. #%%$ or YEAH!!) because it does not mention anything about that in the description? Thank you very much in advance.

My program works perfectly fine on the given testcases but gives me 0 when i submit it? IS my code completely wrong? Thank You

also read announcement
http://wcipeg.com/comments/view#3719

Each word consists of letters of the alphabet and exactly one space separates adjacent words.

do we "absorb" all the inputs to we output, or do we output them as soon as the inputs appear?

you output for each input in order. So the second one.

...the Judge just wouldn't accept it.

Do you need a blank line between the last line of input and the first line of output, too?

I got the exact smae problem Xiao Lei, it works well for all posibilities on my compiler, but I get 0/10 on the judge

Well, looks like you didn't test for multiple lines.

O.o-By multiple lines Hanson do you mean if one of the test cases is longer than the screen or multiple testcases

I mean multiple cases.
(The judge's "screen" is infinite, so no need to worry about stuff like that)

Oh, ok, but it still works fine. The only doubts I may have is punctuation like a period, but thats not mentioned in the problem and it seems like it works fine for others, and spacing. Would spacing like this correct

3
Hello world

**** ****

this is so very random

**** is so **** random

finally i am done

finally i am ****

e.g. " Here's " -> " ****'s "

There are no apostrophes in the test data. There is a test case which consists just of the word "Four", and you haven't censored it.

Thanks a lot! It turned out that I forgot one of the conditions lol...

No idea what your problem is, the judge does not accept your solution, even with correct spacing.

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.

-Toby Li