hihocoder:Give My Text Back

一、题目

时间限制: 10000ms
单点时限: 1000ms
内存限制: 256MB

描述

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 <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
    vector<string> input;
    string word = "";
    char c;
    while (cin >> noskipws >> c){
        if (isalpha(c)){
            if (c >= 'A'&&c <= 'Z')
                c += 32;
            word += c;
        }
        else{
            if (word != ""){
                input.push_back(word);
                word = "";
            }
            if (c != ' ')
                input.push_back(to_string(c));
        }
    }
    int n = input.size();
    bool isFirst = true;
    for (int i = 0; i < n; i++){
        if (input[i] == "44")
            cout << ',';
        else if (input[i] == "46"){
            cout << '.';
            isFirst = true;
        }
        else if (input[i] == "10")
            cout << endl;
        else{
            if (i>0 && input[i - 1] != "10")
                cout << " ";
            if (isFirst){
                input[i][0] -= 32;
                isFirst = false;
            }
            cout << input[i];
        }
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

fullstack_lth

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值