zjnu2017校赛 E 会长大人的异世界生活(模拟题)

http://acm.zjnu.edu.cn/xiaosai/contests/1000/problems/1004.html


/*
1.输入
2.特殊处理空串的情况,有分隔符号在开头,中间,结尾(分倒数第二个是不是分隔符号两种情况,注意注释)
3.处理其他情况

新的知识点:
1.关于tring
    .clear();
    .empty();
    +=44;√
    +=tmp(string类型);√
2.函数的重要性......
*/


#include<cstdio>
#include<cstring>
#include<iostream>
#include<string>
using namespace std;

string s;
string a,b,tmp;
int judge(char c){
    if(c==44||c==59)    return 1;
    else return 0;
}
int isInt(string tmp){
    int len=tmp.length();
    int flag1=0,flag2=0;
    for(int i=0;i<len;i++){
        if(!(tmp[i]<='9'&&tmp[i]>='0'))  return 0;
        else{
            if(tmp[i]=='0'){
                if(!flag1&&!flag2)    flag1=1;
                else if(flag1&&!flag2)  return 0;
            }
            else{
                if(flag1&&!flag2)   return 0;
                else{
                    flag2=1;
                }
            }
        }
    }
    return 1;
}
int main()
{
    cin>>s;
  //  cout<<s<<endl;
    int len=s.length();
    tmp.clear();
    for(int i=0;i<len;i++){
        if(i==0&&judge(s[0])||i>0&&judge(s[i])&&judge(s[i-1])){//出现空串的过程,
            if(!b.empty())  b+=44;
            b+=" ";//判断空串
            if(i==len-1){//如果最后一个和倒数第二个都是分隔符号
                if(!b.empty())  b+=44;
                b+=' ';
                tmp.clear();
            }
            tmp.clear();
            continue;
        }
        //对非空串的处理
        if(!judge(s[i])){
            tmp+=s[i];
        }
        else{
         //   cout<<tmp<<endl;
            if(isInt(tmp)){
                if(!a.empty()) a+=44;
                a+=tmp;
                tmp.clear();
            }
            else{
                if(!b.empty())  b+=44;
                b+=tmp;
                tmp.clear();
            }
            if(i==len-1){//如果最后一个是分隔的符号并且前一个不是分隔符号
                if(!b.empty())  b+=44;
                b+=' ';
                tmp.clear();
            }
        }
    }
    if(!tmp.empty()){
        if(isInt(tmp)){
            if(!a.empty()) a+=44;
            a+=tmp;
            tmp.clear();
        }
        else{
            if(!b.empty())  b+=44;
            b+=tmp;
            tmp.clear();
        }
    }
    if(!a.empty()){
        cout<<'\"';
        int l=a.length();
        for(int i=0;i<l;i++)
            if(a[i]!=' ')   cout<<a[i];
        cout<<'\"'<<endl;
    }
    else{
        cout<<'-'<<endl;
    }
    if(!b.empty()){
        cout<<'\"';
        int l=b.length();
        for(int i=0;i<l;i++)
            if(b[i]!=' ')   cout<<b[i];
        cout<<'\"'<<endl;
    }
    else{
        cout<<'-'<<endl;
    }
    return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值