<cf>Sysadmin Bob

B. Sysadmin Bob
time limit per test
2 seconds
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 1and 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

AC code:

#include <cstdio>
#include <queue>
#include <iostream>
using namespace std;

int main()
{
    char s[202];
    char c;
   // int cnt1=0,cnt2=0;//cnt1、cnt2分别记录字母和@的个数
    queue <int> pos;//记录出现@处的下标
    bool OK=1;//判断是否能还原
    int len,i,j;
    for(len=0,i=0;scanf("%c",&c)!=EOF;len++)
    {//cout<<1;
        if(c=='\n' || c=='\r')
        {
            s[len]='\0';
            break;
        }
        else if(c=='@')
        {
            //两个@间距不足两位,注意要在pos不为空时才执行。
            if(!pos.empty() && len-pos.back()<3)
            {//cout<<"*";
                OK=0;
                while(scanf("%c",&c) && !(c=='\n' || c=='\r')){}
                break;
            }
            s[len]=c;
            pos.push(len);
        }
        else
        {
            s[len]=c;
            //cnt1++;
        }
    }
    if(OK)
    {
        //如果不存在@ or 不存在字母 or 首字符是@ or 末字符是@
        if(pos.empty() || !(len-pos.size()) || s[len-1]=='@' || s[0]=='@')
        {
            OK=0;
        }
        else
            for(i=0;s[i]!='\0';)
            {
                if(pos.size()>1)
                {
                    for(;i<pos.front()+2;i++)
                        cout<<s[i];
                    cout<<",";
                    pos.pop();
                }
                else
                {
                    for(;s[i]!='\0';i++)
                        cout<<s[i];
                    cout<<endl;
                }
            }
    }
    if(!OK) cout<<"No solution"<<endl;
    return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值