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 ...
随机推荐
- 查看tablespace实际使用量和剩余空间
到某表空间所有段的加和值,即按表空间分组统计dba_data_files.bytes-dba_free_space.bytes=dba_segments.bytesdba_segments中可查询已分 ...
- java 访问器方法中对象引用的问题
"注意不要编写返回引用可变对象的访问器方法".因为会破坏类的封装性,引用的内容可能会被改变,产生业务逻辑上的错误. 什么是可变对象? 先要搞清楚java中值传递和引用传递的问题,总结如下: 1.对象就 ...
- 开学了!这些Linux认证你要知道。
导读 大家好,今天我们将认识一些非常有价值的全球认可的Linux认证.Linux认证是不同的Linux专业机构在全球范围内进行的认证程序.Linux认证可以让Linux专业人才可以在服务器领域或相关公 ...
- 有效处理java异常的三个原则
Java中异常提供了一种识别及响应错误情况的一致性机制,有效地异常处理能使程序更加健壮.易于调试.异常之所以是一种强大的调试手段,在于其回答了以下三个问题: 什么出了错? 在哪出的错? 为什么出错? ...
- redis错误汇总
1.redis因为内存不够而启动失败 Microsoft Open Tech group 在 GitHub上开发了一个REDIS Win64的版本,项目地址是:https://github.com/M ...
- (原创)LAMP教程5-配置VirtualBox虚拟机中centos6.4的网卡
(原创)LAMP教程5-配置VirtualBox虚拟机中centos6.4的网卡 是的,今天我们要讲的是如何配置VirtualBox虚拟机中centos6.4的网卡,毕竟我们是要做网站开发的,没有网络 ...
- 动态执行linq 语句 NLinq
using Evaluant.NLinq.Memory;using System.Collections.Generic;using Evaluant.NLinq;using System.Colle ...
- 告别where 1=1 最佳方案分享
已经有2年没有用过where 1=1了,没想到换了家公司后,又让我看到了它.在网络上面搜索了一下,发现没有人提供一个比较好的方案来解决这一问题.很多人说可以让数据库的优化机制去处理,但是,我想对于大部 ...
- 【Linux学习】 包含子目录的makefile简单应用
1 .目录结构 practice6 / ui / ui.h ui.c practice6 / dal / dal.h dal.c practice6 / bll / bll.h bll.c pr ...
- springmvc基础知识
springmvc框架,类似于struts,主要用于MVC的控制层 spring的简单配置(非注解): spring-mvc.xml文件(springMVC框架的基本文件) web.xml文件 ja ...