【Educational Codeforces Round 2A】【模拟】Extract Numbers 分离数串和字符串
2015-11-29 19:54
627 查看
A. 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 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 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
output
input
output
input
output
input
output
Note
In the second example the string s contains
five words: "1", "", "01", "a0",
"".
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 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 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",
"".
//http://blog.csdn.net/snowy_smile
#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<math.h>
#include<iostream>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<bitset>
#include<algorithm>
#include<time.h>
using namespace std;
void fre(){freopen("c://test//input.in","r",stdin);freopen("c://test//output.out","w",stdout);}
#define MS(x,y) memset(x,y,sizeof(x))
#define MC(x,y) memcpy(x,y,sizeof(x))
#define MP(x,y) make_pair(x,y)
#define ls o<<1#define rs o<<1|1typedef long long LL;
typedef unsigned long long UL;
typedef unsigned int UI;
template <class T> inline void gmax(T &a,T b){if(b>a)a=b;}
template <class T> inline void gmin(T &a,T b){if(b<a)a=b;}
const int N=1e5+10,M=0,Z=1e9+7,ms63=1061109567;
char s
;
string a,b;
int main()
{
while(~scanf("%s",s))
{
int l=strlen(s);s[l]=';';
int p=0;
bool flag=0;
a="";int numa=0;
b="";int numb=0;
for(int i=0;i<=l;++i)
{
if(s[i]==','||s[i]==';')
{
s[i]=0;
if(!flag&&s[p]!=0)
{
if(++numa==1)a+=s+p;
else {a+=",";a+=s+p;}
}
else
{
if(++numb==1)b+=s+p;
else {b+=",";b+=s+p;}
}
p=i+1;
flag=0;
}
else if(!isdigit(s[i]))flag=1;
else if( (i==0||s[i-1]==0) && s[i]=='0'&&isdigit(s[i+1]))flag=1;
}
if(numa==0)a="-";
else a='"'+a+'"';
if(numb==0)b="-";
else b='"'+b+'"';
cout<<a<<endl<<b<<endl;
}
return 0;
}
/*
【题意】
若干个字符串在一行。
字符串有数串(无前导零)和其他串,之间用','或';'分隔。
让你把两种类型的串在两行分别输出。
【类型】
模拟
【分析】
直接模拟即可。
1,数串的判定除了数字全为digit外,还要求没有前导零。
2,可以用末尾赋值为0的方法做串赋值串合并操作。
【时间复杂度&&优化】
O(|s|)
*/
相关文章推荐
- C++11学习笔记(三)
- Spring MVC设置首页,403,404,500页面
- Java设计模式四: 原型模式(Prototype Pattern)
- 油菜花王国——杭电校赛(并查集)
- VS连接MySQL·:Unable to connect to any of the specified MySQL hosts(VS连接MySQL出错)
- linux基础之uboot load address、entry point、 bootm address以及kernel运行地址的意义及联系
- 记软件构建之法的读书笔记
- 极光推送没你想象的那么难
- Hive笔记--配置以及遇到的问题
- MySql之输入Emoji表情
- Iterator(迭代器)的使用
- iOS_使用NSXMLParser解析本地XML文件
- 木心短语
- 你所浪费的今天,是昨天死去的人奢望的明天
- 短作业优先(SJF)算法
- git笔记
- (解题报告)Uva-1225 --- Digit Counting
- SharedPreferences详解
- 华东交通大学2015年ACM“双基”程序设计竞赛1002
- 1070. Mooncake