#include <cstdio> #include <iostream> #include <string> #include <sstream> using namespace std; int main(){ string str; while(cin>>str){ if(str.length()<=3){ cout<<str<<endl; continue; } stringstream ss(str); string temp; string end; while(getline(ss,temp,',')){ end+=temp;//凭接 } int len=end.length(); int n=len%3; int count=0; for(int i=0;i<n;i++){ cout<<end[i]; } if(n!=0){ cout<<","; } for(int i=n;i<len;i++){ if(count<2||i==len-1){ cout<<end[i]; count++; } else if(count==2){ cout<<end[i]<<","; count=0; } } cout<<endl; } return 0; } |
Double click to view unformatted code.