HDU 3129 The Brave Sir Robin’s cAsE cOrReCtOr(字符串处理)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3129

Problem Description

Dissatisfied with the loud 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 would 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 could at least lower their voices. This, he reasoned, could be accomplished by replacing
upper case letters with lower case letters ("Case correction", from his perspective). These modifications could 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 performing "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.

Input

The input file contains the text that you are converting. Your conversions should be based on the rules given by Brave Sir Robin above.

Output

The 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. a
ray 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. A
ray of sunlight made him jump from his own shadow with a face as pale as chalk.

Source

2006 ACM-ICPC Pacific Northwest Region

题意:

就是把‘.’,‘ !‘, ‘?‘ 后面的第一个字母变为大写,其余的全小写!

PS:

注意‘.’,‘ !‘, ‘?‘ 后面有多个‘ ‘, ‘(‘ , ‘)‘的情况!

然后就是换行也相当于是一个空格!

代码如下:

#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. a
ray 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. a
ray of sunlight made him jump from his own shadow with A FACE AS PALE AS CHALK.
*/
时间: 2024-12-28 06:02:47

HDU 3129 The Brave Sir Robin’s cAsE cOrReCtOr(字符串处理)的相关文章

hdu 2296 aC自动机+dp(得到价值最大的字符串)

Ring Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3180    Accepted Submission(s): 1033 Problem Description For the hope of a forever love, Steven is planning to send a ring to Jane with a rom

【HDU】1846 Brave Game

http://acm.hdu.edu.cn/showproblem.php?pid=1846 题意:二人博弈,1堆石子每次取1~m个,没有石子可取的输,输出先手胜利还是后手胜利. #include <cstdio> using namespace std; int main() { int c; scanf("%d", &c); while(c--) { int n, m; scanf("%d%d", &n, &m); print

【HDU 1846】 Brave Game

[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=1846 [算法] 巴什博弈 若有(m+1)个石子,显然先手不能直接取完,后手必胜 因此,我们可以把石子总数表示为 : n = k(m+1) + r 若r不为0,则先手取走r个,若后手取s个,先手取(m + 1 - s)个,只要保证留给对手的石子数是(m+1)的倍数即可,先手必胜 否则,先手必败 [代码] #include<bits/stdc++.h> using namespace std; i

HDU 3518 Boring counting(后缀数组啊 求字符串中不重叠的重复出现至少两次的子串的个数)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3518 Problem Description 035 now faced a tough problem,his english teacher gives him a string,which consists with n lower case letter,he must figure out how many substrings appear at least twice,moreover

HDU 1062.Text Reverse【栈或数组或字符串流】【字符处理】【8月30】

Text Reverse Problem Description Ignatius likes to write words in reverse way. Given a single line of text which is written by Ignatius, you should reverse all the words and then output them. Input The input contains several test cases. The first lin

hdu 4908 BestCoder Sequence 发现M中值是字符串数, 需要预处理

BestCoder Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 271    Accepted Submission(s): 112 Problem Description Mr Potato is a coder. Mr Potato is the BestCoder. One night, an amazing

HDU 5414(2015多校10)-CRB and String(字符串处理)

题目地址:HDU 5414 题意:要求判断字符串s能否通过添加若干个字符得到字符串t 思路:这个题看起来复杂,其实仔细一分析,成功转化只包含两种情况.第一种因为要求插入的新字符和它前面的字符c不同,如果t中有x个连续的c,那么在s中也必须有x个连续的c:第二种是s必须是t的一个不连续子串. #include <stdio.h> #include <math.h> #include <string.h> #include <stdlib.h> #include

HDU 2072.单词数【STL的优势以及字符串流的使用】【8月4】

单词数 Problem Description lily的好朋友xiaoou333最近很空,他想了一件没有什么意义的事情,就是统计一篇文章里不同单词的总数.下面你的任务是帮助xiaoou333解决这个问题. Input 有多组数据,每组一行,每组就是一篇小文章.每篇小文章都是由小写字母和空格组成,没有标点符号,遇到#时表示输入结束. Output 每组只输出一个整数,其单独成行,该整数代表一篇文章里不同单词的总数. Sample Input you are my friend # Sample

HDU 3068 最长回文 (manacher算法)

最长回文 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 9188    Accepted Submission(s): 3159 Problem Description 给出一个只由小写英文字符a,b,c...y,z组成的字符串S,求S中最长回文串的长度. 回文就是正反读都是一样的字符串,如aba, abba等 Input 输入有多组