(CodeForces
来源:互联网 发布:杜兰特2016西决数据 编辑:程序博客网 时间:2024/06/18 04:24
(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; }
- codeforces~~~
- Codeforces
- codeforces
- Codeforces
- codeforces
- codeforces
- Codeforces
- Codeforces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- 打开MySQL数据库远程访问的权限
- jDK7中的String.intern()方法
- HDU2089 不要62 数位dp
- PathMeasure的基本使用
- JDBC使用步骤
- (CodeForces
- 如何解决“504 Gateway Time-out”错误
- JavaScript编程精解第九章:正则表达式
- 虚拟机下CentOS安装JDK
- Linux中常用操作命令
- 大话设计模式之代理模式
- VS C# WinForm对于EXCEL表的操作
- 嵌入式编程常考的无符号数和有符号数的运算问题
- 2015-2016 Northwestern European Regional Contest I.Identifying Map Tiles(超级技巧+脑洞)