Question link: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 3129
Problem description
Dissatisfied with the authorization and constant pronouncements of his alleged misdeeds by a trio of indefatigable minstrels, the brave knight Sir Robin wishes to exercise his authority by modifying their lyrics. the minstrels were happy to provide printed transcripts of their songs, and cheerfully announced that they wocould not change a word of them.
Undaunted, the brave (and crafty) Sir Robin scrutinized the documents and noticed that their loudest inflections were indicated by capital letters and realized that he cocould at least lower their voices. this, he reasoned, cocould be accomplished by replacing upper case letters with lower case letters ("case correction", from his perspective ). these modifications cocould be forced upon the singers by insistence upon proper usage of the King's English. not all letters can be lower case, however, as the King's English mandates some letters must be upper case.
Strangely hesitant about faster Ming "case correction" personally, the brave, crafty (and managerially capable) Sir Robin humbly requests you write a program to perform a first pass of case correction for the songs. there will still be some corrections required after this program is used.
As your program reads the file, it must force to upper case all alphabetic characters that follow terminal punctuation marks (period, question mark, and exclamation point) with only white space or parentheses characters following. all other alphabetic characters are to be forced to lower case. note that decimal numbers are not to be followed by an upper case character unless the number itself is followed by a terminal punctuation mark.
Inputthe input file contains the text that you are converting. Your conversions shoshould be based on the rules given by Brave Sir Robin abve.
Outputthe output is to be the converted text. All characters are transferred to the output. Some will have case correction, others will be directly copied.
Sample Input
The Brave Sir Robin took a short walk in a dark forest where rabbits did stalk. aray of sunlight made him jump from his own shadow with A FACE AS PALE AS CHALK.
Sample output
the brave sir robin took a short walk in a dark forest where rabbits did stalk. Aray of sunlight made him jump from his own shadow with a face as pale as chalk.
Source2006 ACM-ICPC Pacific Northwest Region
Question:
Is to put '.','! ','? 'The first letter after the letter is changed to uppercase, and the rest are all lowercase!
PS:
Note '.','! ','? 'There are multiple backend!
The line feed is equivalent to a space!
The Code is as follows:
#include <cstdio>#include <cstring>#include <algorithm>#include <iostream>using namespace std;int main(){ char s[1017]; int tt = 0; while(gets(s)) { tt++; int len = strlen(s); for(int i = 0; i < len; i++) { if(i == 0 && tt > 1) { while(s[i]==' ' || s[i]=='(' || s[i]==')') { i++; if(i >= len) break; } s[i] = toupper(s[i]); } else if(s[i]=='.' || s[i]=='!' || s[i]=='?') { i++; while(s[i]==' ' || s[i]=='(' || s[i]==')') { i++; if(i >= len) break; } s[i] = toupper(s[i]); } else { s[i] = tolower(s[i]); } } printf("%s\n",s); } return 0;}/*The Brave Sir Robin took a short walk in a dark forest where rabbits did stalk. aray of sunlight made him jump from his own shadow with A FACE AS PALE AS CHALK.The Brave Sir Robin took a short walk in a dark forest where rabbits did stalk. aray of sunlight made him jump from his own shadow with A FACE AS PALE AS CHALK.*/
HDU 3129 the Brave Sir Robin's case Corrector (string processing)