CodeForces 31B Sysadmin Bob

B. Sysadmin Bob
time limit per test
0.5 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Input

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 «@».

Output

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.

Sample test(s)
Input
a@aa@a
Output
a@a,a@a
Input
a@a@a
Output
No solution
Input
@aa@a
Output
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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值