Educational Codeforces Round 2 A. Extract Numbers 模拟题
A. Extract Numbers
Time Limit: 20 Sec
Memory Limit: 256 MB
题目连接
http://codeforces.com/contest/600/problem/A
Description
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 strings).
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 Input
aba,123;1a;0
Sample Output
"123,0"
"aba,1a"
HINT
题意
给你一行字符串,然后让你分别出,哪些是没有含有前导0的整数
哪些是字符串
题解:
单纯的模拟题,注意,小数也是字符串,其他就没什么了
代码:
#include<iostream>
#include<stdio.h>
#include<vector>
using namespace std; string s;
vector<string>A[];
int main()
{
cin>>s;
int flag = ;
string S;
for(int i=;i<s.size();i++)
{
if(s[i]==';'||s[i]==',')
{
if(flag==)
{
if(S.size()!=&&S[]=='')
flag = ;
if(S.size()==)
flag = ;
}
A[flag].push_back(S);
flag = ;
S="";
}
if(s[i]<='Z'&&s[i]>='A')
{
S+=s[i];
flag = ;
}
if(s[i]<='z'&&s[i]>='a')
{
S+=s[i];
flag = ;
}
if(s[i]<=''&&s[i]>='')
{
S+=s[i];
}
if(s[i]=='.')
{
S+=s[i];
flag = ;
}
}
if(flag==)
{
if(S.size()!=&&S[]=='')
flag = ;
if(S.size()==)
flag = ;
}
A[flag].push_back(S);
if(A[].size()==)
{
printf("-\n");
}
else
{
printf("\"");
for(int i=;i<A[].size();i++)
{
if(i!=A[].size()-)
cout<<A[][i]<<",";
else cout<<A[][i]<<"\""<<endl;
}
}
if(A[].size()==)
{
printf("-\n");
}
else
{
printf("\"");
for(int i=;i<A[].size();i++)
{
if(i!=A[].size()-)
cout<<A[][i]<<",";
else cout<<A[][i]<<"\""<<endl;
}
}
}
Educational Codeforces Round 2 A. Extract Numbers 模拟题的更多相关文章
- Educational Codeforces Round 2 A. Extract Numbers
打开题目链接 题意:输入一个字符串,用,或:分隔输出字符串和整数(不含前导0和浮点数) ACcode: #include <iostream> #include <cstdio> ...
- Educational Codeforces Round 11B. Seating On Bus 模拟
地址:http://codeforces.com/contest/660/problem/B 题目: B. Seating On Bus time limit per test 1 second me ...
- Educational Codeforces Round 8 D. Magic Numbers 数位DP
D. Magic Numbers 题目连接: http://www.codeforces.com/contest/628/problem/D Description Consider the deci ...
- Educational Codeforces Round 8 D. Magic Numbers
Magic Numbers 题意:给定长度不超过2000的a,b;问有多少个x(a<=x<=b)使得x的偶数位为d,奇数位不为d;且要是m的倍数,结果mod 1e9+7; 直接数位DP;前 ...
- Educational Codeforces Round 52D(ARRAY,模拟最短路)
#include<bits/stdc++.h>using namespace std;int n,x;int chess[17*17];//记录棋盘上的numberarray<int ...
- Educational Codeforces Round 7 B. The Time 水题
B. The Time 题目连接: http://www.codeforces.com/contest/622/problem/B Description You are given the curr ...
- Educational Codeforces Round 7 A. Infinite Sequence 水题
A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/622/problem/A Description Consider the ...
- Educational Codeforces Round 11 A. Co-prime Array 水题
A. Co-prime Array 题目连接: http://www.codeforces.com/contest/660/problem/A Description You are given an ...
- Educational Codeforces Round 10 C. Foe Pairs 水题
C. Foe Pairs 题目连接: http://www.codeforces.com/contest/652/problem/C Description You are given a permu ...
随机推荐
- HashMap的两种遍历方式
HashMap的两种遍历方式 HashMap存储的是键值对:key-value . java将HashMap的键值对作为一个整体对象(java.util.Map.Entry)进行处理,这优化了Hash ...
- Android -- Support包特性
干货 每一个 Support 包版本后缀 vX 所代表的含义是他能够被使用的最低版本等级.之所以无法在更低版本进行使用的原因,是因为随着版本的升级,在新版本中有很多之前不支持的特性或者 API,因此如 ...
- getDeclaredMethods()和getMethods()区别
getDeclaredMethods() 返回 Method 对象的一个数组,这些对象反映此 Class 对象表示的类或接口声明的所有方法,包括公共.保护.默认(包)访问和私有方法, ...
- 位图引起的内存溢出OutOfMemory解决方案
一.问题描述:Android下的相机在独自使用时,拍照没有问题,通过我们的代码调用时,也正常,但是更换了不同厂商的平板,ROM由Android4.0变成了Android4.1后,拍照出现了OutOfM ...
- 【Mongo】Linux安装MongoDB
呵呵哒,每天都是小惊喜. 一 下载 https://www.mongodb.org/downloads可进行下载,根据需要选择合适的版本和操作系统 二 上传服务器 1 上传服务器路径并解压 2 创建数 ...
- 《Python核心编程》 第十章 错误和异常
10–1. 引发异常. 以下的哪个因素会在程序执行时引发异常? 注意这里我们问的并不是异常的原因. a) 用户 b) 解释器 c) 程序 d) 以上所有 e) 只有 b) 和 c) f) 只有 a) ...
- 【Opencv 小工具】鼠标选区信息获取
有时候在目标跟踪的算法初始化工作时候,需要选区一个Rect区域,来表示要跟着的目标,所以有次小工具. 使用QT和opencv 编写 项目地址 https://github.com/wzyuliyang ...
- C++的笔记学习第一篇,认识C++
在一个类中包含两种成员: 数据和函数,分别称为C++数据成员和成员函数. 关于类: 类是C++新增加的重要数据类型,有了类,就就可以实现面向对象程序设计方法中的封装.信息隐蔽.继承.派生.多态等功能. ...
- 如果你喜欢Python 那么你不得不知的几个开源项目
1.Trac Trac拥有强大的bug管理 功能,并集成了Wiki 用于文档管理.它还支持代码管理工具Subversion ,这样可以在 bug管理和Wiki中方便地参考程序源代码. Trac有着比较 ...
- bzoj 2393 Cirno的完美算数教室(容斥原理+搜索)
[题意] 定义C数为只包含数字2和9的数,求[L,R]内能被C数整除的个数. [思路] Dfs预处理出C数,并去除其中倍数的情况. Dfs搜索出现情况,奇数加,偶数减,当数值大于R时剪枝. [代码] ...