(CodeForces - 600A)Extract Numbers

这道题目要求从输入字符串中找出所有非负整数,并构造两个新字符串a和b。a包含所有找到的数字,用逗号分隔;b包含其余的单词,保持原始顺序。如果找不到数字,a显示'-';如果所有都是数字,b显示'-'。
摘要由CSDN通过智能技术生成

(CodeForces - 600A)Extract Numbers

time limit per test:2 seconds
memory limit per test:256 megabytes
input:standard input
output:standard 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.

Examples

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”, “”.

题目大意:对于一个字符串,如果是数字就放到a串(这个数字不能是前导为0的数可以使单独一个0),如果不是就放到b串,最后输出a串和b串。如果a串或者b串没有字符就输出’-‘,其他的细节问题以及输出各种多看看题目,就是一道模拟题,模拟它的过程就行了。

思路:

#include<cstdio>
#include<cstring>
#include<string>
using namespace std;

const int maxn=100005;
char s[maxn],tmp[maxn];
char a[maxn],b[maxn];
int tot,tota,totb;

void getstr()
{
    bool flag=false;
    int cnt=0;
    if(!tot)
    {
        b[totb++]=',';
        return;
    }
    for(int i=0;i<tot;i++)
        if(tmp[0]!='0'&&isdigit(tmp[i])) cnt++;
    if((tot==1&&tmp[0]=='0')||cnt==tot) flag=true;
    if(flag)
    {
        for(int i=0;i<tot;i++) a[tota++]=tmp[i];
        a[tota++]=',';
    }
    else
    {
        for(int i=0;i<tot;i++) b[totb++]=tmp[i];
        b[totb++]=',';
    }
}

int main()
{
    while(~scanf("%s",s))
    {
        int len=strlen(s);
        tot=0;
        tota=totb=0;
        for(int i=0;i<len;i++)
        {
            if(s[i]==','||s[i]==';')
            {
                getstr();
                tot=0;
            }
            else tmp[tot++]=s[i];
        }
        getstr();
        a[tota-1]='\0';
        b[totb-1]='\0'; 
        if(!tota) printf("-\n");
        else printf("\"%s\"\n",a);
        if(!totb) printf("-\n");
        else printf("\"%s\"\n",b);
    }
    return 0;   
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值