codeforces Educational Codeforces Round 2 A. Extract Numbers
2015-11-29 16:28
447 查看
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
a
Note
In the second example the string s contains five words: “1”, “”, “01”, “a0”, “”.
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”
inputa
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; }
相关文章推荐
- Codeforces Round #197 (Div. 2)
- Codeforces Round #198 (Div. 1)
- Codeforces 405E Codeforces Round #238 (Div. 2)E
- Codeforces 407C Codeforces Round #239 (Div. 1)C
- CodeForces 449A - Jzzhu and Chocolate
- CodeForces 449 B. Jzzhu and Cities
- Codeforces Round #265 (Div. 2)
- Codeforces #310 div2 C. Case of Matryoshkas
- 状态压缩DP codeforces 244 Problem C. The Brand New Function 和 codeforces 165 E. Compatible Numbers
- codeforces 16 Problem E fish
- Codeforces Round332 部分题解
- Codeforces round #247 for Div. 2
- Codeforces Round #246 (Div. 2)
- Codeforces #264(div 2)D.Gargari and Permutations
- Codeforces Round #236 (Div. 2)------A,B
- codeforces 257 div2 B
- Codeforces Gym100571A Cursed Query
- Codeforces Gym100342E Minima
- Codeforces Gym100342J Triatrip
- Codeforces Gym100286B Blind Walk (dfs)