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("-\n");
    }
    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("-\n");
    }
    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;
        }
    }
}

 

转载于:https://www.cnblogs.com/qscqesze/p/5005372.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值