hihocoder:Give My Text Back
来源:互联网 发布:skycc营销软件怎么样 编辑:程序博客网 时间:2024/04/27 23:30
一、题目
- 样例输入
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.
描述
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.
二、思路
本题是字符串输入输出的处理。
三、代码
#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;}
- hihocoder:Give My Text Back
- # hihocoder #1197 : Give My Text Back
- hihocoder 1197 : Give My Text Back
- hihocoder 1197 Give My Text Back
- 微软笔试题 《Give My Text Back》
- Give My Text Back_hihoCoder
- Give Me Back My Digital Rights!
- [2016 微软预科生计划-探星夏令营在线测试2] Give My Text Back(字符串处理)
- Give Me My Place to Smoke!
- 庆祝My blog come back!
- my first bolg text
- COLOR MY TEXT
- Color my text
- Give my best wishes to you in Thanksgiving Day!
- Give my best wishes to you in Thanksgiving Day!
- My Lost Certificates Come back Magically
- Back Up of My Blog Page-Skin
- Back to my blog on CSDN
- Linux文件操作
- 43. Multiply Strings
- Java 编码注意
- axis1.4生成客户端代码
- 使用ejs编译后,内容会转义的解决办法
- hihocoder:Give My Text Back
- JVM:FullGC
- RMQ - ST算法
- React快速入门教程
- 加盐哈希函数与验证函数,可用户注册与登录
- Android中Service 全解析
- 1.vue项目例子——webpack安装
- 微信消息推送 -java
- iOS 汉字转UTF-8编码