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


题意:

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

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.
*/


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
字符串哈希滑动窗口是一种用于处理字符串的算法。它主要用于在给定的字符串中找到满足特定条件的子串。 在字符串哈希滑动窗口算法中,我们首先计算原始字符串的哈希值。然后,我们使用一个滑动窗口来遍历字符串,每次滑动一个固定长度的窗口。我们可以通过比较每个窗口内的子串的哈希值来判断是否满足条件。 具体而言,我们可以使用BKDRHash等哈希函数来计算字符串的哈希值。然后,我们枚举每个可能的起点,并使用滑动窗口来计算窗口内的子串的哈希值。通过比较窗口内的子串的哈希值,我们可以判断是否满足条件。 对于滑动窗口的移动,如果窗口内的子串满足条件,我们可以继续将窗口往右移动一个固定的长度。如果窗口内的子串不满足条件,我们将窗口的右边界移到最右端,并依次比较新窗口内的子串的哈希值。 综上所述,字符串哈希滑动窗口算法是通过计算字符串的哈希值,并使用滑动窗口来遍历字符串,以找到满足特定条件的子串。这个算法可以高效地处理字符串,并且能够应用于各种字符串相关的问题。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [String (字符串哈希+滑动窗口)](https://blog.csdn.net/weixin_43872264/article/details/107571742)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* *3* [【字符串hash+滑动窗口】String HDU - 4821](https://blog.csdn.net/qq_45599865/article/details/111143633)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值