[模拟]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类
接着看怎么添加单词,如果当前是第一个加进的单词,就不用在前面加','分割,直接添加当前单词,否则先添一个','再添如当前单词
输出时如果某个类为空则输出'-',否则用引号""括起答案输出
***/
[模拟]Educational Codeforces Round 2A Extract Numbers的更多相关文章
- Educational Codeforces Round 32
http://codeforces.com/contest/888 A Local Extrema[水] [题意]:计算极值点个数 [分析]:除了第一个最后一个外,遇到极值点ans++,包括极大和极小 ...
- [Educational Codeforces Round 16]C. Magic Odd Square
[Educational Codeforces Round 16]C. Magic Odd Square 试题描述 Find an n × n matrix with different number ...
- Educational Codeforces Round 37
Educational Codeforces Round 37 这场有点炸,题目比较水,但只做了3题QAQ.还是实力不够啊! 写下题解算了--(写的比较粗糙,细节或者bug可以私聊2333) A. W ...
- Educational Codeforces Round 35 (Rated for Div. 2)
Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...
- Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes
Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://code ...
- Educational Codeforces Round 63 (Rated for Div. 2) 题解
Educational Codeforces Round 63 (Rated for Div. 2)题解 题目链接 A. Reverse a Substring 给出一个字符串,现在可以对这个字符串进 ...
- Educational Codeforces Round 58 (Rated for Div. 2) 题解
Educational Codeforces Round 58 (Rated for Div. 2) 题目总链接:https://codeforces.com/contest/1101 A. Min ...
- Educational Codeforces Round 35 A. Nearest Minimums【预处理】
[题目链接]: Educational Codeforces Round 35 (Rated for Div. 2) A. Nearest Minimums time limit per test 2 ...
- Educational Codeforces Round 26
Educational Codeforces Round 26 困到不行的场,等着中午显示器到了就可以美滋滋了 A. Text Volume time limit per test 1 second ...
随机推荐
- 重大改革!Python,最接近人工智能的语言~将被加入高考科目!
就在前几天,和一位浙江省高校的信息技术老师聊天,我得到了一个震惊的消息: 明年,浙江省信息技术教材将不会在使用晦涩难懂的VB语言,而是改学更简单易懂的Python语言.也就是说, Python语言将纳 ...
- Nginx_安装
1. 安装步骤 上传nginx上传nginx安装包到linux 安装gcc 1 yum -y install gcc-c++ gcc 查看是否安装gcc: 1 gcc -v 安装依赖库 1 yum - ...
- 2016/11/10 吃吃喝喝Hacking Thursday Night聚餐活动 at Dunkin Donuts
店名:Dunkin Donuts 唐恩都乐 点评:http://www.dianping.com/shop/21378231 地址:静安区南京西路1649号静安公园内(近静安公园) 走法:地铁2号线静 ...
- 对话|人工智能先驱Yoshua Bengio
Bengio"> 今年1月份,微软收购深度学习初创公司Maluuba时,Maluuba公司德高望重的顾问.深度学习先驱Yoshua Bengio也接手了微软的人工智能研究顾问 ...
- A01 React+Antdesign 开发环境准备
B站教程视频 https://www.bilibili.com/video/av38372336?from=search&seid=1131449710389099812 1 安装node.j ...
- IDEA中Git的使用详解
原文链接:https://www.cnblogs.com/javabg/p/8567790.html 工作中多人使用版本控制软件协作开发,常见的应用场景归纳如下: 假设小组中有两个人,组长小张,组员小 ...
- 正式学习MVC 05
1.剃须刀模板razor的使用 1)混编 循环语法 @model List<MVCStudy.Models.Student> @{ ViewBag.Title = "List&q ...
- safari坑之 video
博客地址: https://www.seyana.life/post/19 本来是打算给博客左上角的gif做个优化, 把gif换成webm,以video的形式自动播放,能从180k降到50k, 现在浏 ...
- 简单的节流函数throttle
在实际项目中,总会遇到一些函数频繁调用的情况,比如window.resize,mouseover,上传进度类似的触发频率比较高的函数,造成很大的性能损耗,这里可以使用节流函数来进行性能优化,主要是限制 ...
- Vue2.0 【第一季】第3节 v-for指令:解决模板循环问题
目录 Vue2.0 [第一季] 第3节 v-for指令:解决模板循环问题 第三节 v-for 指令 一.基本用法: 二.排序 三.对象循环输出 Vue2.0 [第一季] 第3节 v-for指令:解决模 ...