微软笔试题 《Give My Text Back》
2016-07-16 21:11
260 查看
时间限制: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:
Each sentence contains at least one word, begins with a letter and ends with a period.
In a sentence the only capitalized letter is the first letter.
In a sentence the words are separated by a single space or a comma and a space.
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:
Changing the cases of letters.
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.
简单的字符串处理题。
需要注意不能输出多余的空格,比如一行末尾如果有多个空格的话,一个也不能输出。如果是单词和逗号(或句号)之间的空格都不能输出,单词和单词之间的多个空格只能输出一个。逗号(或句号)和单词之间的多个空格只能输出一个
单点时限: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:
Each sentence contains at least one word, begins with a letter and ends with a period.
In a sentence the only capitalized letter is the first letter.
In a sentence the words are separated by a single space or a comma and a space.
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:
Changing the cases of letters.
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 <cstdio> int main() { int blank = 0, end = 1;//end表示一句话是否结束 //如果已经结束,下一个字母需要大写 int pos; char c; while(~scanf("%c", &c)){ if (c == '.'){ putchar(c); end = 1; }else if (c == ' '){ blank = 1; }else if (c == '\n'){ putchar('\n'); end = 1; blank = 0; }else if (c == ','){ putchar(','); }else { if (end){ if (c > 'Z'){ c -= 32; } }else{ if (c < 'a'){ c += 32; } } if (blank){ putchar(' '); } putchar(c); end = 0; blank = 0; } } return 0; }
相关文章推荐
- [OpenGL] 从顶点坐标到光栅化(渲染管线)
- Layout基本属性总结
- C++ PP Chapter IX 内存模型和名称空间
- 欢迎使用CSDN-markdown编辑器
- CodeForces 584D Dima and Lisa
- 游戏光枪坐标定位原理及算法
- vector使用需要注意的一些问题
- 【Dubbo实战】 Dubbo+Zookeeper+Spring整合应用篇-Dubbo基于Zookeeper实现分布式服务(二)
- 深夜支持现场解决软件问题纪实
- 再聊HDFS Erasure Coding
- Hibernate开发之数据检索方式
- 如果子结果编号为i,求其父节点编号
- MySQL中的存储引擎讲解(InnoDB,MyISAM,Memory等各存储引擎对比)
- 天线设计(中)
- Genymotion 模拟器 VirtualBox
- 通过HttpURLConnection获取网络图片实例
- 带你从零了解mysql
- hdu 1789 Doing Homework again 贪心
- dubbo学习之dubbo管理控制台装配及集成zookeeper集群部署(1)
- SVN客户端的使用