zoukankan      html  css  js  c++  java
  • 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;
            }
        }
    }
  • 相关阅读:
    Ajax_ajax模板引擎 ---tmplate.js处理数据和标签拼接
    Ajax_ajax请求中的跨域问题---浏览器不允许ajax跨域获取服务器数据,那我们就用jsonp来实现跨域
    Ajax_jquery库中Ajax方法的使用
    第一阶段冲刺 second day
    第11周周总结
    用户场景分析
    第一阶段冲刺 first day
    第10周周总结
    第9周周总结
    查找水王
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5005372.html
Copyright © 2011-2022 走看看