[模拟]Educational Codeforces Round 2A Extract Numbers
2 seconds
256 megabytes
standard input
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".
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.
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 wordsare numbers print dash on the second line.
aba,123;1a;0
"123,0"
"aba,1a"
1;;01,a0,
"1"
",01,a0,"
1
"1"
-
a
-
"a"
In the second example the string s contains five words: "1", "", "01", "a0", "".
题意:
给你一个字符串,以‘,’或‘;’来分割单词,并让你给单词分类,a类放没有前导0的非负整数单词,b类放除a类以外的单词,如果某个类为空则输出'-',否则用引号""括起答案输出
思路:
现在我们以单词结尾的','或‘;’来进行分割,但一开始输入的字符串如果末尾为‘,’或‘;’,则还应统计一个空格,但这个空格末尾没有','或';'来给我判断,所以为了统一,我们在结尾加上';'
接着要统计a类和b类单词个数
如果到了一个单词的结束分割符','或';',则把则个字符标记为分割符,并判断要把当前单词加入a类还是b类,默认当前单词是a类,如果当前单词存在一个非整数位或有前导零则当前单词属于b类
接着看怎么添加单词,如果当前是第一个加进的单词,就不用在前面加','分割,直接添加当前单词,否则先添一个','再添如当前单词
输出时如果某个类为空则输出'-',否则用引号""括起答案输出
#include<bits/stdc++.h>
using namespace std;
const int amn=1e5+;
char s[amn],a[amn],b[amn],tmp[amn];
struct index{
int st,ed;
}idx[amn];
int main(){
ios::sync_with_stdio();
cin>>s;
int len=strlen(s);
s[len]=';'; ///现在我们以单词结尾的','或‘;’来进行分割,但一开始输入的字符串如果末尾为‘,’或‘;’,则还应统计一个空格,但这个空格末尾没有','或';'来给我判断,所以为了统一,我们在结尾加上';'
int st=,ed=,tp=;
int atp=,btp=,f=,it=; ///atp和btp分别是统计a类和b类单词个数
for(int i=;i<=len;i++){
if(s[i]==','||s[i]==';'){ ///到了一个单词的结束
s[i]=;
if(f&&s[it]){
if(++atp==)strcat(a,s+it); ///如果当前是第一个加进的单词,就不用在前面加','分割,直接添加当前单词
else strcat(a,","),strcat(a,s+it); ///否则先添一个','再添如当前单词
}
else{
if(++btp==)strcat(b,s+it);
else strcat(b,","),strcat(b,s+it);
}
it=i+;
f=; ///默认是符合条件的非负整数
}
else if(s[i]<''||s[i]>''||((i==||s[i-]==)&&s[i]==''&&(s[i+]>=''&&s[i+]<='')))f=; ///如果当前单词存在一个非整数位或有前导零则当前单词属于b类
}
int alen=strlen(a),blen=strlen(b);
if(atp){
printf("\"");
for(int i=;i<alen;i++){
printf("%c",a[i]);
}
printf("\"\n");
}
else{ ///如果没单词,则输出-下面同理
printf("-\n");
}
if(btp){
printf("\"");
for(int i=;i<blen;i++){
printf("%c",b[i]);
}
printf("\"\n");
}
else{
printf("-\n");
}
}
/***
给你一个字符串,以‘,’或‘;’来分割单词,并让你给单词分类,a类放没有前导0的非负整数单词,b类放除a类以外的单词,如果某个类为空则输出'-',否则用引号""括起答案输出
现在我们以单词结尾的','或‘;’来进行分割,但一开始输入的字符串如果末尾为‘,’或‘;’,则还应统计一个空格,但这个空格末尾没有','或';'来给我判断,所以为了统一,我们在结尾加上';'
接着要统计a类和b类单词个数
如果到了一个单词的结束分割符','或';',则把则个字符标记为分割符,并判断要把当前单词加入a类还是b类,默认当前单词是a类,如果当前单词存在一个非整数位或有前导零则当前单词属于b类
接着看怎么添加单词,如果当前是第一个加进的单词,就不用在前面加','分割,直接添加当前单词,否则先添一个','再添如当前单词
输出时如果某个类为空则输出'-',否则用引号""括起答案输出
***/
最新文章
- 在VS里配置及查看IL
- C# “配置系统未能初始化” 异常解决
- Tween + 缓动函数
- Tomcat Context配置(转)
- python计算文件的行数和读取某一行内容的实现方法
- js获取上传文件内容(未完待续)
- SVM推导
- python登陆教务管理系统
- HTC T328W刷机包 仿三星S5 UI美化 精简 S5落下
- iPad开发中UIPopoverController的使用
- Jquery那些坑
- spring学习笔记一 入门及配置
- Linux-01初级学习
- vue2入坑随记(一)-- 初始全家桶
- 2017-12-04 编写Visual Studio Code插件初尝试
- Java线程池ThreadPoolExecutor&;&;Executors
- python爬取微信信息--显示性别/地域/词云(附代码)
- HDU4328 Cut the cake(动规:最大子矩形问题/悬线法)
- 【gRPC使用问题1】gRPC的proto内import其他proto导致的一次小坑
- [jquery] 遮罩弹窗,点击遮罩弹窗自动隐藏