CCC '11 S1 - English or French?

View as PDF

Points: 5
Time limit: 2.0s
Memory limit: 256M

Problem type
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 and T characters than s and S characters, we will say that it is (probably) English text;
• if the given text has more s and S characters than t and T characters, we will say that it is (probably) French text;
• if the number of t and T characters is the same as the number of s and S 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.)

• commented on Dec. 18, 2022, 1:35 p.m. edited

This comment is hidden due to too much negative feedback. Show it anyway.

• commented on Dec. 18, 2022, 6:23 p.m. edit 3

consider this sample:

sssssssssssssssssssssss
t
t

your code would output 'English', even though there are more 's' characters in total. (also, don't post code in comments)

• commented on Dec. 18, 2022, 3:33 p.m. edit 2

This comment is hidden due to too much negative feedback. Show it anyway.

• commented on Dec. 18, 2022, 6:19 p.m. edited

noo volcano dont quit youre very smart and helpful

• commented on Nov. 22, 2022, 3:14 p.m.

I'm really at a loss here. I've run my code through every sample I can think of and it always gives the correct answer, but when I try to submit it, I'm told it gives a wrong answer...

• commented on Dec. 18, 2022, 1:32 p.m.

that is happening to me too

• commented on Oct. 17, 2022, 10:45 a.m.

I can't get past test case 8. Any ideas to help a new guy out?

• commented on Oct. 18, 2022, 7:10 p.m. edit 2

compare the occurrences of the letters t and T to the occurrences of the letters s and S

The problem statement clearly says to check for uppercase and lowercase characters.

Also, here's a tip: Instead of using a for loop, you can utilize Python's inbuilt count function.

• commented on Oct. 19, 2022, 6:52 p.m.

Good suggest! Thank you so much! You help me a lot!

• commented on Oct. 20, 2022, 1:15 p.m.

happy to help :)

• commented on Oct. 19, 2022, 3:07 p.m.

I thought I handled the uppercase/lowercase issue using the .lower(). I'll give the .count() a shot and see what happens, thanks.

• commented on Oct. 19, 2022, 5:06 p.m. edit 2

You aren't reading all the input. There will be N+1 lines of input (N lines of actual text). You only read a single line of input.

You should use the DMOJ Discord server to get help faster.

• commented on Sept. 6, 2022, 10:38 p.m.

I submit my code, and it can not pass through all the test? What is the problem of my code?

• commented on Sept. 7, 2022, 12:39 p.m.

Check the input specification. You need to be reading N lines of text

• commented on July 31, 2022, 6:09 p.m.

I don't understand the input in this problem. For Python do we just have the one input N? for example:(n = int(input). Or do we have to somehow code to receive an unknown amount of input?

• commented on Aug. 1, 2022, 9:40 a.m.

So say the first input is n, then you have to make the code input n number of times before it ends. In example one, the first value was 3 so the code only allowed to input 3 other lines of codes.

• commented on April 16, 2022, 11:22 a.m.

Make sure you remember to check for capital letters as well!

• commented on Feb. 8, 2022, 1:36 p.m. edit 3

im lost, my thing reads all three lines and is outputting correctly. what am i missing?

• commented on Feb. 8, 2022, 3:12 p.m.

Your code only looks at the last line of text. Try a test case with two lines of English and one line of French.

• commented on Feb. 8, 2022, 3:45 p.m.

OH, ok thanks! I was testing if the first one was messed up only!

• commented on Dec. 17, 2021, 2:06 a.m.

This comment is hidden due to too much negative feedback. Show it anyway.

• commented on May 5, 2022, 10:23 a.m.

This comment is hidden due to too much negative feedback. Show it anyway.

• commented on Jan. 25, 2022, 12:50 a.m.

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.

• commented on Jan. 25, 2022, 7:57 a.m.

The number represents the number of lines of text. Your code fails because it only looks at the first one.

• commented on Sept. 26, 2021, 8:09 p.m. edited

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

• commented on Dec. 9, 2020, 11:04 a.m.

Does anyone know how to solve time limit issues with java in case 4?

• commented on Dec. 9, 2020, 1:30 p.m.

There's some repeated code in your submission that can be condensed. Also, consider writing a more efficient solution.

• commented on Dec. 9, 2020, 2:24 p.m.

Ok, thank you!

• commented on Sept. 7, 2019, 10:07 p.m. edit 2

The question states:

if the number of t and T characters is the same as the number of s and S characters, we will say that it is (probably) French text.

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?

• commented on Sept. 7, 2019, 10:45 p.m. edited

You are forgetting that C/C++ style input stops with all whitespace characters, so doing this:

string str;
cin >> str;


will read but a single word from the first line of the input. What you should be doing is reading the entire line:

string str;
getline(cin, str);

• commented on Sept. 7, 2019, 11:04 p.m.

I already AC'd by hard-coding, but why does this solution using getline WA case 3?

• commented on Sept. 7, 2019, 11:12 p.m.

You should insert cin.ignore() between lines 9 and 10 to ignore the new line character which has not been read by cin >> N.

• commented on Sept. 7, 2019, 11:20 p.m.

Worked, thank you!

• commented on Aug. 24, 2019, 1:11 a.m.

Can anyone tell me what's wrong with my test case 3?

• commented on Aug. 24, 2019, 10:20 a.m.

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.

• commented on Sept. 4, 2021, 6:53 p.m.

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.

• commented on Feb. 10, 2019, 10:47 a.m.

I'm not sure what's wrong with my code, I failed test case 3. Can someone help?

• commented on Feb. 10, 2019, 11:38 a.m. edited

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.

• commented on Feb. 10, 2019, 6:10 p.m.

It worked thank you so much!

• commented on Dec. 25, 2018, 11:47 a.m.

I speak french, and t actually works at guessing the language! Cool problem!

• commented on Dec. 21, 2017, 10:32 a.m.

This comment is hidden due to too much negative feedback. Show it anyway.

• commented on Dec. 21, 2017, 12:09 p.m.

if the given text has more t and T characters than s and S characters

Your program only counts then individually

• commented on Dec. 21, 2017, 2:16 p.m.

i do not just count but i've compared the caracters between them too?

• commented on Oct. 23, 2017, 6:03 p.m.

I dont see how i could get test case 3 wrong. Its just a simple comparison...

• commented on Oct. 23, 2017, 7:47 p.m.

Try rereading the problem statement, especially the classification criteria.

• commented on Oct. 24, 2017, 5:57 p.m.

The problem was that i had an int scanner before a String

• commented on Nov. 26, 2019, 9:07 a.m.

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 a Scanner#nextLine to it.

• commented on March 20, 2016, 4:49 p.m.

This comment is hidden due to too much negative feedback. Show it anyway.

• commented on March 20, 2016, 6:48 p.m.

Either use StringBuilder or process each line as you read it. Concatenating all the lines takes time.