zoukankan      html  css  js  c++  java
  • CF600A Extract Numbers

    题意:

    给一个字符串,里面的小字符串用','或者';'分开,筛选出所有的不含前导0的数字存在一个字符串里面,并用','分开

    其余字符串存在另一个字符串里面,空字符串也要存,存在第二个字符串里面。

    此题模拟即可

    因为要判断前导0的时候

    第一位出现1~9以外或以后的位数出现0~9进入非数字串

    其他的主要是string库的运用

    和输出  ” 时要打转义符 ‘’

    实现如下:

    #include <algorithm>
    #include <iostream>
    #include <cmath>
    #include <cstring>
    #include <map>
    #include <string>
    #include <vector>
    #include <queue>
    #include <stack>
    #include <cstdio>
    #include <cstdlib>
    using namespace std;
    typedef long long ll;
    inline int read()
    {
        register int p(1),a(0);register char ch=getchar();
        while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
        if(ch=='-') p=-1,ch=getchar();
        while(ch>='0'&&ch<='9') a=a*10+ch-48,ch=getchar();
        return a*p;
    }
    vector<string> m;
    string a,cx,cy;
    int n,la=0;
    int che(int x,int y)
    {
        if(y<x) return 0;
        if(x==y&&a[x]=='0') return 1;
        if(a[x]<='0'||a[x]>'9') return 0;
        for(int i=x;i<=y;i++) if(a[i]<'0'||a[i]>'9') return 0;
        return 1;
    }
    int main()
    {
    //    freopen("input","r",stdin);
    //    freopen("output","w",stdout);
        getline(cin,a);
        a+=';';
        n=a.size();
        for(int i=0;i<n;i++)
        {
            if(a[i]==','||a[i]==';')
            {
                if(che(la,i-1))
                    cx=cx+','+a.substr(la,i-la);
                else
                    cy=cy+','+a.substr(la,i-la);
                la=i+1;
            }
        }
        if(n=cx.size())
        {
            printf(""");
            for(int i=1;i<n;i++) printf("%c",cx[i]);
            printf(""
    ");
        }
        else puts("-");
        if(n=cy.size())
        {
            printf(""");
            for(int i=1;i<n;i++) printf("%c",cy[i]);
            printf(""
    ");
        }
        else puts("-");
        return 0;
    }
  • 相关阅读:
    CCF 认证
    ZOJ Light Bulb
    codeforce 605BE. Freelancer's Dreams
    HDU2546——背包DP——饭卡
    转载DD大神背包九讲
    背包九讲
    zstu4186——线段树——表白计划(未完成)
    zstu4189——后缀表达式——逻辑运算
    蛇形矩阵
    zs深入浅出学算法022——DFS———汉诺塔问题II
  • 原文地址:https://www.cnblogs.com/cold-cold/p/10074267.html
Copyright © 2011-2022 走看看