Canadian Computing Competition: 2011 Stage 1, Senior #1
You would like to do some experiments in natural language processing. Natural language processing (NLP) involves using machines to recognize human languages.
Your first idea is to write a program that can distinguish English text from French text.
After some analysis, you have concluded that a very reasonable way of distinguishing these two languages is to compare the occurrences of the letters t
and T
to the occurrences of the letters s
and S
. Specifically:
- if the given text has more
t
andT
characters thans
andS
characters, we will say that it is (probably) English text; - if the given text has more
s
andS
characters thant
andT
characters, we will say that it is (probably) French text; - if the number of
t
andT
characters is the same as the number ofs
andS
characters, we will say that it is (probably) French text.
Input Specification
The input will contain the number
followed by
lines of text, where each line has at least one character and no more than
characters.
Output Specification
Your output will be one line. This line will either consist of the word English (indicating the text is probably English) or French (indicating the text is probably French).
Sample Input 1
3
The red cat sat on the mat.
Why are you so sad cat?
Don't ask that.
Output for Sample Input 1
English
Sample Input 2
3
Lorsque j'avais six ans j'ai vu, une fois,
une magnifique image,
dans un livre
Output for Sample Input 2
French
(Note: Sample Input 2 is the first sentence of Le Petit Prince by Antoine de Saint-Exupéry.)
Sample Input 3
4
Si je discernais ta voix encore
Connaissant ce coeur qui doute,
Tu me dirais de tirer un trait
Quoi que partir me coute.
Output for Sample Input 3
English
(Note: Sample Input 3 is added by DMOJ from Le Fantôme de l'Opéra.)
Comments
Make sure you remember to check for capital letters as well!
im lost, my thing reads all three lines and is outputting correctly. what am i missing?
Your code only looks at the last line of text. Try a test case with two lines of English and one line of French.
OH, ok thanks! I was testing if the first one was messed up only!
A gentle reminder for all dumb people like me, the code takes TWO different inputs. A number and a string of text. Keep this in mind while writing the code.
@akshay7892 I am not dumb, I do not accept this even if it should be a gentle reminder.
Ok, but for what is the integer? it does not make any sense. im getting a wrong answer just on one test, if u could take a look at my code and say in what im messing it, i would be grateful. Thanks bro.
The number represents the number of lines of text. Your code fails because it only looks at the first one.
how do I keep getting test case two wrong i've tested my code out on tons of stuff and it seems functional to me anybody know why?
nvm I had a uppercase letter where I shouldnt have
Does anyone know how to solve time limit issues with java in case 4?
There's some repeated code in your submission that can be condensed. Also, consider writing a more efficient solution.
Ok, thank you!
The question states:
However, in test case 3, I output the number of t's and s's and apparently there is 0 of each of them. But the solution is "English". I had to hardcode it to solve the problem. Please do something about it.
Edit: or was there a problem with my code?
You are forgetting that C/C++ style input stops with all whitespace characters, so doing this:
will read but a single word from the first line of the input. What you should be doing is reading the entire line:
I already AC'd by hard-coding, but why does this solution using getline WA case 3?
You should insert
cin.ignore()
between lines 9 and 10 to ignore the new line character which has not been read bycin >> N
.Worked, thank you!
Can anyone tell me what's wrong with my test case 3?
Your submission is testing each line for its language individually and then choosing the language that appeared most often in all the lines. But that's not what the question asks for.
Thx, I couldn't figure out what was wrong in my code. English is not my mother language so can't pick up subtle things. I thought that "given text" was referring to each input text line. With your comment I realize it was referring to the full text.
I'm not sure what's wrong with my code, I failed test case 3. Can someone help?
I don't see anything wrong with your actual code. I believe that the problem is that right after you have scanner.nextInt(), when you use scanner.nextLine() it actually reads the same line of the integer, meaning it would read nothing. So just use an extra scanner.nextLine() in between your reading of "a" and your lines, and don't use it. That hopefully should fix the problem.
It worked thank you so much!
I speak french, and t actually works at guessing the language! Cool problem!
I think that my submission is totaly true but i got just 40, any help or idea about what's going wrong please?!
Your program only counts then individually
i do not just count but i've compared the caracters between them too?
I dont see how i could get test case 3 wrong. Its just a simple comparison...
Try rereading the problem statement, especially the classification criteria.
The problem was that i had an int scanner before a String
To be more specific,
Scanner#nextInt
doesn't go to the new line of the input. In order to force it onto the next line, you need to append aScanner#nextLine
to it.This comment is hidden due to too much negative feedback. Show it anyway.
Read the statement again (about equal).
This comment is hidden due to too much negative feedback. Show it anyway.
Either use
time.
StringBuilder
or process each line as you read it. Concatenating all the lines takesThis comment is hidden due to too much negative feedback. Show it anyway.