hiho一下第107周《Give My Text Back》
2016-07-17 16:04
411 查看
题目链接:传送门
题目大意:给你多组格式不标准的字符串句子,要你恢复到标准格式(单词中间只有一个空格或者一个逗号一个空格,句子的首字母大写其他小写,遇到回车也要换行)
题目思路:直接按题意模拟,注意几个标记变量的状态改变就行
题目大意:给你多组格式不标准的字符串句子,要你恢复到标准格式(单词中间只有一个空格或者一个逗号一个空格,句子的首字母大写其他小写,遇到回车也要换行)
题目思路:直接按题意模拟,注意几个标记变量的状态改变就行
#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <algorithm> #include <cstring> #include <stack> #include <cctype> #include <queue> #include <string> #include <vector> #include<functional> #include <set> #include <map> #include <climits> #define lson root<<1,l,mid #define rson root<<1|1,mid+1,r #define fi first #define se second #define ping(x,y) ((x-y)*(x-y)) #define mst(x,y) memset(x,y,sizeof(x)) #define mcp(x,y) memcpy(x,y,sizeof(y)) using namespace std; #define gamma 0.5772156649015328606065120 #define MOD 1000000007 #define inf 0x3f3f3f3f #define N 30005 #define maxn 100005 typedef pair<int,int> PII; typedef long long LL; char ch; string st=""; int main(){ int i,j,x,y; int dax=1,kong=0; while(cin>>noskipws>>ch){ if(isalpha(ch)){ ch=tolower(ch); if(dax){ if(kong)st+=" "; st+=toupper(ch); dax=0; } else{ st+=ch; } kong=1; } else{ if(ch==','){ if(st[st.length()-1]==' ')st[st.length()-1]=','; else st+=','; st+=" "; kong=0; } else if(ch=='.'){ if(st[st.length()-1]==' ')st[st.length()-1]='.'; else st+='.'; kong=1; dax=1; } else if(ch==' '||ch=='\t'){ if(kong){ st+=" "; kong=0; } } else if(ch=='\n'){ if(st!=""){ int len=st.length(); for(i=len-1;i>=0;--i)if(st[i]!=' ')break; st=st.substr(0,i+1); cout<<st<<endl; dax=1;kong=0; st=""; } } } } return 0; }
相关文章推荐
- 翻翻git之---低内存损耗,简单易用的汉字->拼音转换库 TinyPinyin
- Codeforces 617E XOR and Favorite Number(莫队算法)
- CSS3 nth 伪类选择器
- sort();方法
- linux df 命令
- AtCoder Grand Contest 001 B - Mysterious Light
- 对象数组与普通数组的区别
- 单调栈1004 scu2801 正方形
- ios 谓词
- 源码分析-java-AbstractList-Itr和ListItr的实现
- Android JNI的Android.mk文件语法详解
- MySQL数据库(1)----入门级操作
- C语言字符串操作总结大全
- sed
- 单调栈1003 scuoj3329 Maximum Submatrix II
- 中软实训随记
- Super A^B mod C 快速幂+欧拉函数降幂
- pom.xml简介
- poj --3614 Sunscreen
- 数据结构(8) 构造数组的MaxTree