Sicily 1463. The Brave Sir Robin’s cAsE cOrReCtOr

本文详细介绍了如何通过编程实现文本中的大写字母转换为小写,并根据特定规则调整标点符号。适用于文本处理、编程初学者以及希望提升文本编辑技能的读者。

1463. The Brave Sir Robin’s cAsE cOrReCtOr

Constraints

Time Limit: 5 secs, Memory Limit: 32 MB

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.

// Problem#: 1463
// Submission#: 3313665
// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/
// All Copyright reserved by Informatic Lab of Sun Yat-sen University
#include <iostream>
#include <cctype>
#include <string>
using namespace std;

int main()
{
    bool first = true;
    string s;
    while ( getline( cin, s ) ) {
        for ( int i = 0; i < s.size(); i++ ) {
            if ( i == 0 && !first ) {
                while ( i < s.size() && ( s[ i ] == '(' || s[ i ] == ')' ) )
                    i++;
                s[ i ] = toupper( s[ i ] );
            }
            else if ( s[ i ] == '.' || s[ i ] == '?' || s[ i ] == '!' ) {
                do {
                    i++;
                } while ( i < s.size() && ( s[ i ] == ' ' || s[ i ] == '(' || s[ i ] == ')' ) );
                if ( i == s.size() )
                    break;
                s[ i ] = toupper( s[ i ] );
            }
            else
                s[ i ] = tolower( s[ i ] );
        }
        first = false;
        cout << s << endl;
    }

    return 0;

}                                 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值