zoukankan      html  css  js  c++  java
  • <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;
    }
    


  • 相关阅读:
    windows 2019 server系统中网卡里面的“详细信息”空白,无法连接网络
    Python一些插件安装
    pip版本过旧,提示要升级pip
    Mac idea 默认全局配置maven设置
    Java并发/多线程-锁的区别与使用
    Java反射的理解
    Git远程连接GitHub添加远程库
    部署Django云服务器 Gunicorn + Nginx
    Nginx在 Centos 没有sites-available 和 sites-enabled目录
    java基础学习笔记4(maven)
  • 原文地址:https://www.cnblogs.com/cszlg/p/2910491.html
Copyright © 2011-2022 走看看