题意:Polycarp wants to add and remove spaces in the string s to ensure the following:
each comma is followed by exactly one space (if the comma is the last character in the string, this rule does not apply to it),
each “three dots” term is preceded by exactly one space (if the dots are at the beginning of the string, this rule does not apply to the term),
if two consecutive numbers were separated by spaces only (one or more), then exactly one of them should be left,
there should not be other spaces.
input
1,2 ,3,…, 10
output
1, 2, 3, …, 10
input
1,,,4…5……6
output
1, , , 4 …5 … …6
input
…,1,2,3,…
output
…, 1, 2, 3, …
分类需要输出空格的情况
’ , ’ 后面需要一个空格
‘……’ 六个’ . ’ 之间需要一个空格
’ , ’ ’ , ’ 之间需要空格
首位0不能输出
通过一次一次的更新flag的数值来确定字符前面的情况
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <vector>
using namespace std;
const int N=300,INF=0x3f3f3f3f;
char s[N];
int main()
{
gets(s);
int flag=0;
for(int i=0;s[i];i++)
{
if(s[i]=='.')
{
if(flag!=0) printf(" ");
printf("...");
i+=2;
flag=1;
}
else if(s[i]>='0'&&s[i]<='9')
{
if(flag!=0&&flag!=1) printf(" ");
if(s[i]=='0'&&(s[i+1]>='0'&&s[i+1]<='9')) continue;
for(;s[i]>='0'&&s[i]<='9';i++)//输出数字
printf("%c",s[i]);
i--;
flag=2;
}
else if(s[i]==',')
{
if(flag==3) printf(" ");
printf("%c",s[i]);
flag=3;
}
}
}