• Educational Codeforces Round 2 A. Extract Numbers 模拟题


    A. Extract Numbers

    Time Limit: 20 Sec

    Memory Limit: 256 MB

    题目连接

    http://codeforces.com/contest/600/problem/A

    Description

    You are given string s. Let's call word any largest sequence of consecutive symbols without symbols ',' (comma) and ';' (semicolon). For example, there are four words in string "aba,123;1a;0": "aba", "123", "1a", "0". A word can be empty: for example, the strings=";;" contains three empty words separated by ';'.

    You should find all words in the given string that are nonnegative INTEGER numbers without leading zeroes and build by them new string a. String a should contain all words that are numbers separating them by ',' (the order of numbers should remain the same as in the string s). By all other words you should build string b in the same way (the order of numbers should remain the same as in the strings).

    Here strings "101", "0" are INTEGER numbers, but "01" and "1.0" are not.

    For example, for the string aba,123;1a;0 the string a would be equal to "123,0" and string b would be equal to "aba,1a".

    Input

    The only line of input contains the string s (1 ≤ |s| ≤ 105). The string contains only symbols '.' (ASCII 46), ',' (ASCII 44), ';' (ASCII 59), digits, lowercase and uppercase latin letters.

    Output

    Print the string a to the first line and string b to the second line. Each string should be surrounded by quotes (ASCII 34).

    If there are no words that are numbers print dash (ASCII 45) on the first line. If all words are numbers print dash on the second line.

    Sample Input

    aba,123;1a;0

    Sample Output

    "123,0"
    "aba,1a"

    HINT

    题意

    给你一行字符串,然后让你分别出,哪些是没有含有前导0的整数

    哪些是字符串

    题解:

    单纯的模拟题,注意,小数也是字符串,其他就没什么了

    代码:

    #include<iostream>
    #include<stdio.h>
    #include<vector>
    using namespace std;
    
    string s;
    vector<string>A[2];
    int main()
    {
        cin>>s;
        int flag = 0;
        string S;
        for(int i=0;i<s.size();i++)
        {
            if(s[i]==';'||s[i]==',')
            {
                if(flag==0)
                {
                    if(S.size()!=1&&S[0]=='0')
                        flag = 1;
                    if(S.size()==0)
                        flag = 1;
                }
                A[flag].push_back(S);
                flag = 0;
                S="";
            }
            if(s[i]<='Z'&&s[i]>='A')
            {
                S+=s[i];
                flag = 1;
            }
            if(s[i]<='z'&&s[i]>='a')
            {
                S+=s[i];
                flag = 1;
            }
            if(s[i]<='9'&&s[i]>='0')
            {
                S+=s[i];
            }
            if(s[i]=='.')
            {
                S+=s[i];
                flag = 1;
            }
        }
        if(flag==0)
        {
            if(S.size()!=1&&S[0]=='0')
                flag = 1;
            if(S.size()==0)
                flag = 1;
        }
        A[flag].push_back(S);
        if(A[0].size()==0)
        {
            printf("-
    ");
        }
        else
        {
            printf(""");
            for(int i=0;i<A[0].size();i++)
            {
                if(i!=A[0].size()-1)
                    cout<<A[0][i]<<",";
                else cout<<A[0][i]<<"""<<endl;
            }
        }
        if(A[1].size()==0)
        {
            printf("-
    ");
        }
        else
        {
            printf(""");
            for(int i=0;i<A[1].size();i++)
            {
                if(i!=A[1].size()-1)
                    cout<<A[1][i]<<",";
                else cout<<A[1][i]<<"""<<endl;
            }
        }
    }
  • 相关阅读:
    ModuleNotFoundError: No module named '_ctypes' make: *** [install] 错误 1
    Python安装常见问题:ModuleNotFoundError: No module named '_ctypes' 解决办法
    No module named 'requests'
    python 安装bs4
    python 判断字符串中是否包含数字
    python lambda与zip 组合使用
    Python 从两个List构造Dict
    针对led显示图案的设计工具,画出图案后,可以导出点阵的16进制数组
    支付宝接口:系统有点忙,一会再试试
    urllib.error.URLError: urlopen error SSL: CERTIFICATE_VERIFY_FAILED certificate verify failed
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5005372.html
Copyright © 2020-2023  润新知