Email address in Berland is a string of the form A@B, where A and B are arbitrary strings consisting of small Latin letters.
Bob is a system administrator in «Bersoft» company. He keeps a list of email addresses of the company's staff. This list is as a large string, where all addresses are written in arbitrary order, separated by commas. The same address can be written more than once.
Suddenly, because of unknown reasons, all commas in Bob's list disappeared. Now Bob has a string, where all addresses are written one after another without any separators, and there is impossible to determine, where the boundaries between addresses are. Unfortunately, on the same day his chief asked him to bring the initial list of addresses. Now Bob wants to disjoin addresses in some valid way. Help him to do that.
The first line contains the list of addresses without separators. The length of this string is between 1 and 200, inclusive. The string consists only from small Latin letters and characters «@».
If there is no list of the valid (according to the Berland rules) email addresses such that after removing all commas it coincides with the given string, output No solution. In the other case, output the list. The same address can be written in this list more than once. If there are several solutions, output any of them.
a@aa@a
a@a,a@a
a@a@a
No solution
@aa@a
No solution
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
int len;
char s[210];
scanf("%s",s);
len=strlen(s);
if(s[0]=='@'||s[len-1]=='@'||count(s,s+len,'@')==0){
cout<<"No solution"<<endl;
}
else{
vector<string> token;
int n=0;
bool ok=true;
for(int i=0;i<len-1;i++){
if(s[i]=='@'&&s[i+1]=='@'){
ok=false;
}
}
for(int i=0;i<len;){
if(s[i]=='@'){
i++;
}
else{
string aux;
int e=i;
while(e<len&&s[e]!='@'){
aux+=s[e];
e++;
}
token.push_back(aux);
n++;
i=e;
}
}
if(n>2){
for(int i=1;i<n-1;i++){
if(token[i].size()==1){//size()指容器当前拥有的元素个数
ok=false;
}
}
}
if(!ok){
cout<<"No solution"<<endl;
return 0;
}
for(int i=0;i<n-1;i++){
string A,B;
if(i==0){
A=token[i];
}
else{
A=token[i].substr(1,token[i].size()-1);//获得字符串token[i]中 从第1位开始的长度为token[i].size()-1的字符串
} //默认时的长度为从开始位置到尾
if(i==n-2){
B=token[i+1];
}
else{
B=token[i+1][0];
}
if(i){
printf(",");
}
printf("%s@%s",A.c_str(),B.c_str());//c_str() 以char*形式传回string 内含字符串
}
printf("\n");
}
return 0;
}