Timus 1601. anticaps requires that the text of an upper-case English letter be converted to an appropriate lower-case English letter.
1601. anticaps
Time Limit: 0.5 second
Memory limit: 64 MB
The blonde Angela has a new whim: Internet chats. Of course, as any blonde, she
Writes her messages using the upper case. You are the moderator of Angela's
Favorite chat and you're fed up with her upper-case messages. The problem
Is that Angela does not respond to your warnings. You decided to write a simple
Anticaps corrector, which wocould make Angela's messages readable.
The correction rules are very simple:
- Sentences in a message consist of words, spaces and punctuation marks.
- Words consist of English letters.
- Sentences end with a full stop, exclamation mark, or question mark.
- The first word of each sentence must start with a capital letter, and all other
Letters of the sentence must be lowercase.
Input
You are given Angela's message, which consists of uppercase English letters,
Spaces, line breaks and punctuation marks: full stops, commas, dashes, colons, exclamation
And question marks. Total length of message is not exceeding 10000 symbols.
Output
Output the corrected message.
Sample
Input |
Output |
Hi there! How did you know I am a blonde? |
Hi there! How did you know I am a blonde? |
Problem Author:Denis musin
Problem Source:Ix usu open personal contest (March 1, 2008)
The answer is as follows (C # language ):
1 using system;
2
3 namespace skyiv. Ben. timus
4 {
5 sealed class t1601
6 {
7 static void main ()
8 {
9 int V;
10 bool iscap = true;
11 while (V = console. In. Read ())! =-1)
12 {
13 char c = (char) V;
14 if (C = '.' | C = '! '| C = '? ') Iscap = true;
15 else if (iscap & char. isupper (c) iscap = false;
16 else if (! Iscap & char. isupper (c) c = Char. tolower (C );
17 console. Write (C );
18}
19}
20}
21}
The C language version is as follows:
1 # include <stdio. h>
2
3 int main ()
4 {
5 Int C, iscap = 1;
6 While (C = getchar ())! = EOF)
7 {
8 If (C = '.' | C = '! '| C = '? ') Iscap = 1;
9 else if (iscap & isupper (c) iscap = 0;
10 else if (! Iscap & isupper (c) c = tolower (C );
11 putchar (C );
12}
13}