noip模拟赛 逃避

题目描述

给定一篇只含有大小写字母,空格以及 ′.′(不含引号)的长度为 L 的文章。文章被若干个 ′.′ 划分 成若干个句子,句子被若干个空格划分成单词。你需要将文章中每个句子第一个单词的首字母改成大写, 其他一律小写,空格与 ′.′ 需原样输出。注意,可能存在某个句子中没有单词,或者某两个单词之间有多 个空格。

输入输出格式

输入格式:

一行,表示原串。

输出格式:

一行,表示你的回答。

输入输出样例

输入样例#1: 
nigeru. wa.haji.
输出样例#1: 
Nigeru. Wa.Haji.
输入样例#2: 
.. .nI noip WEn   le  .NICE broO..
输出样例#2: 
.. .Ni noip wen   le  .Nice broo..

分析:模拟题,打个标记判断这一位是否需要改成大写即可.

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

char s;
bool flag = true;

int main()
{
    while (scanf("%c", &s) != EOF)
    {
        if (s == ' ')
        {
            printf("%c", s);
            continue;
        }
        if (s == '.')
        {
            flag = true;
            printf("%c", s);
            continue;
        }
        if ((s >= 'A' && s <= 'Z') || (s >= 'a' && s <= 'z'))
        {
            if (flag)
            {
                if (s >= 'a' && s <= 'z')
                    s -= 32;
                printf("%c", s);
                flag = false;
                continue;
            }
            else
            {
                if (s >= 'A' && s <= 'Z')
                    s += 32;
                printf("%c", s);
                continue;
            }
        }
        else
            printf("%c", s);
    }

    return 0;
}

原文地址:https://www.cnblogs.com/zbtrs/p/7709594.html