codeforces Educational Codeforces Round 2 A. Extract Numbers

A. Extract Numbers
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
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 string s=”;;” 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 string s).

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 test(s)
input
aba,123;1a;0
output
“123,0”
“aba,1a”
input
1;;01,a0,
output
“1”
“,01,a0,”
input
1
output

“1”

input
a

output

“a”
Note
In the second example the string s contains five words: “1”, “”, “01”, “a0”, “”.

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

bool isnum(char a) {
    if(a == '0'||a == '1'||a == '2'||
       a == '3'||a == '4'||a == '5'||
       a == '6'||a == '7'||a == '8'||
       a == '9'
       ) return 1;
    return 0;
}

int main(){
    ios::sync_with_stdio(false);
    string s,s0;
    vector<string>out1,out2;
    while(cin >> s) {
        s = s+',';
        int flag = 1;
        for(int i = 0; i < s.size(); i++) {

            if(s[i] != ',' && s[i] != ';'){

                s0 += s[i];          
                if(!isnum(s[i])) flag = 0;
            }
            else {         
                    if(s0 == "") {

                        if(out2.size() != 0) out2.push_back(",");
                        out2.push_back("");
                        flag = 1;
                        continue;
                    }
                    if(s0 == "0") {
                        if(out1.size() > 0) out1.push_back(",");
                        out1.push_back("0");
                        flag = 1;
                        s0 = "";
                        continue;
                    }
                if(flag){
                    if(s0[0] == '0') {
                        if(out2.size() != 0) out2.push_back(",");
                       out2.push_back(s0);
                    }
                    else {
                        if(out1.size() != 0) out1.push_back(",");
                     out1.push_back(s0);
                    }

                }

                else {

                   if(out2.size() != 0) out2.push_back(",");
                    out2.push_back(s0);
                }


                s0 = "";
                flag = 1;
            }
        }
        if(out1.size() != 0) {
            cout << "\"";
            for(int i = 0; i < out1.size(); i++) cout << out1[i];
            cout << "\"" << endl;
        }
        else cout << "-" <<endl;

        if(out2.size() != 0) {
            cout << "\"";
            for(int i = 0; i < out2.size(); i++) cout << out2[i];
            cout << "\"" << endl;
        }

        else cout << "-" <<endl;

        s0 = "";
        out1.clear();
        out2.clear();
    }

    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值