• 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;
            }
        }
    }
  • 相关阅读:
    VS2022修改默认字符集
    Unity 实现简单力场效果
    网页前端(Html)video播放m3u8(HLS)&Vue使用video.js播放m3u8
    ORACLE WITH AS 用法
    utf8和utf8mb4的区别
    mysql锁表原因及解决方法
    C#实现Stream、string、byte[]、文件、Bitmap、二进制之间的转换
    Spring循环依赖。为什么是三级缓存,二级不行吗?
    微信小程序 wx:for 遍历 Map集合
    Rust问题解决合集
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5005372.html
Copyright © 2020-2023  润新知