Give My Text Back_hihoCoder

版权声明:本文为博主原创文章,未经博主允许不得转载,谢谢合作! https://blog.csdn.net/cleopard66/article/details/52081829
描述
To prepare for the English exam Little Ho collected many digital reading materials. Unfortunately the materials are messed up by a malware.


It is known that the original text contains only English letters (a-zA-Z), spaces, commas, periods and newlines, conforming to the following format:


1. Each sentence contains at least one word, begins with a letter and ends with a period.


2. In a sentence the only capitalized letter is the first letter.


3. In a sentence the words are separated by a single space or a comma and a space.


4. The sentences are separated by a single space or a single newline.


It is also known the malware changes the text in the following ways:


1. Changing the cases of letters.


2. Adding spaces between words and punctuations.


Given the messed text, can you help Little Ho restore the original text?


输入
A string containing no more than 8192 English letters (a-zA-Z), spaces, commas, periods and newlines which is the messed text.


输出
The original text.


样例输入
my Name  is Little   Hi.
His   name IS Little ho  ,  We are   friends.
样例输出
My name is little hi.

His name is little ho, we are friends.


【我的程序】

#include <stdio.h>
#include <iostream>
using namespace std;

int main()
{
    char c=getchar();
    int flag_sen=1, flag_voc=0;

    while (c!=EOF)
    {
        if (c>='A' && c<='Z')
        {
            if (flag_sen) flag_sen=0; else c+=32;
            if (flag_voc) {cout<<' '; flag_voc=0;}
            cout<<c; c=getchar();
            continue;
        }

        if (c>='a' && c<='z')
        {
            if (flag_sen) {flag_sen=0; c-=32;}
            if (flag_voc) {cout<<' '; flag_voc=0;}
            cout<<c; c=getchar();
            continue;
        }

        if (c==' ') {flag_voc=1; c=getchar(); continue;}

        if (c==',') {cout<<","; flag_voc=1; c=getchar(); continue;}

        if (c=='.') {cout<<c; flag_voc=1; flag_sen=1; c=getchar(); continue;}

        if (c=='\n') {cout<<c; flag_voc=0; flag_sen=1; c=getchar(); continue;}
    }

    return 0;
}


没有更多推荐了,返回首页