CCC '11 S1 - English or French?
View as PDFCanadian 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
tandTcharacters thansandScharacters, we will say that it is (probably) English text; - if the given text has more
sandScharacters thantandTcharacters, we will say that it is (probably) French text; - if the number of
tandTcharacters is the same as the number ofsandScharacters, 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
The DMOJ added testcase is so bad the editor had to clarify he didn't write it💀💀💀
bro i misspelled english into engilsh 😭
if you're stuck, you can combine all the lines into one single massive string and running it through a method that counts the separate amounts of s and ts (since spaces dont matter), hope this helps!
For some reason, you have to set the # of t's > the # of s's in the if loop. If you do it the other way around, then it marks the first case wrong.
Why does sample input three output English when it's clearly French?
It's because even though the language is French, but it fits the question's criteria for English.
If you count the number of
tandTs compared to the number ofsandSs in Sample Input 3, you find this:Number of
s(uppercase and lowercase): 6Number of
t(uppercase and lowercase): 9Since the number of occurrences of
tis greater than the number of occurrences ofs, then we should deem it English.(Just to clarify to anyone else who might've gotten confused)
thanks
english or spanish
both
who ever moves first is g-
*stops breathing and blinking for the rest of my coding class
So, if your input is: '1 English' then the output must be: 'French'
It's really sad that if the check of your code is good, depends on whether you first check French instead of English.