hihocoder:Give My Text Back
2016-07-19 12:42
302 查看
一、题目
时间限制: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.
样例输入
样例输出
二、思路
本题是字符串输入输出的处理。
三、代码
时间限制: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; }
相关文章推荐
- 使用C++实现JNI接口需要注意的事项
- 关于指针的一些事情
- c++ primer 第五版 笔记前言
- share_ptr的几个注意点
- Lua中调用C++函数示例
- Lua教程(一):在C++中嵌入Lua脚本
- Lua教程(二):C++和Lua相互传递数据示例
- C++联合体转换成C#结构的实现方法
- C++高级程序员成长之路
- C++编写简单的打靶游戏
- C++ 自定义控件的移植问题
- C++变位词问题分析
- C/C++数据对齐详细解析
- C++基于栈实现铁轨问题
- C++中引用的使用总结
- 使用Lua来扩展C++程序的方法
- C++中调用Lua函数实例
- Lua和C++的通信流程代码实例
- C++的template模板中class与typename关键字的区别分析
- C与C++之间相互调用实例方法讲解