BlueBook

p129ex5 - Find the Character

Write a program that takes as input a single character and then a sentence, terminated by a period. The program should echo-print the input (that is, print it in the form in which it was read) and give a count of the number of times that the character appears in the sentence. Your program should not be case-sensitive - that is, uppercase letters should be considered equivalent to the corresponding lowercase letters.

Input

The first line of the input consists of one character. The second line of the input consists of a sentence terminated by a period.

Output

Output the number of times the character appears in the sentence.

Sample Input 1

o
Why so serious son.

Sample Output 1

Why so serious son.
3

Sample Input 2

y
You want the truth? You can't handle the truth.

Sample Output 2

You want the truth? You can't handle the truth.
2

All Submissions
Best Solutions


Point Value: 3
Time Limit: 2.00s
Memory Limit: 16M
Added: Oct 22, 2008

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

Comments (Search)

I got 20/30 but after I checked my code I couldn't see what was wrong.
Can someone tell me my problem?

Does your program pass the sample inputs? From what I see, running it on sample input 2 should tell you your issue.

In the Input format, it says to print out the number of times the character appears in the sentence, but in the sample inputs, it shows both the string and the amount of times...... Which are you supposed to do?

"The program should echo-print the input (that is, print it in the form in which it was read) and give a count of the number of times that the character appears in the sentence."

Yes, you should print the string and number of times (this should be in the output format, I guess)

If I leave a space in between each word in the input, it only includes the first word in the sentence.

For example: Why so serious son. --it thinks that only "Why" is part of the sentence.

How do I fix this?

1. Please (re)read the announcement about posting questions about Judge problems.

2. Use the nextLine() method

How do you work out lower or upper case. Is there some kind of special function.

(I am using Pascal).

If character variable 'input' is in lower case then 'upcase(input)' will give you the upper case of the 'input.' Alternatively, you should learn about the ASCII chart. Google 'ASCII table'... But, the upcase should be sufficient to let you get the points for this problem.