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 ...
随机推荐
- 【DFS深搜初步】HDOJ-2952 Counting Sheep、NYOJ-27 水池数目
[题目链接:HDOJ-2952] Counting Sheep Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 ...
- SQL 2005 日志损坏的恢复方法
SQL 在突然停电或者非正常关机下,可能会出现日期文件错误,导致数据库不正常.恢复数据库方法如下 1.数据库服务停掉 将数据库文件备份 例如数据库名为 DTMS 则将 DTMS.mdf 备份出来. 2 ...
- Linux 系统编程
简介和主要概念 Linux 系统编程最突出的特点是要求系统程序员对它们工作的的系统的硬件和操作系统有深入和全面的了解,当然它们还有库和系统调用上的区别. 系统编程分为:驱动编程.用户空间编程和网络编程 ...
- Delphi 让自己的软件实现双击打开文件 转
unit shjAssociateFileType; interface uses Windows, Registry; {将文件类型strFileExtension与程序strExeFileName ...
- IOS 类别
在编写面向对象的程序时,你经常希望向现有的类添加一些新的行为:你总是能够为对象提供使用这些新方法的新手段.当希望为现有的类增加新行为时,我们通常会创建子类,但是有时候子类并不方便.例如,你可能会希望为 ...
- Ubuntu14.04下Python3.4启动IDLE
1.在Ubuntu14.04 LTS版本中,已经自行安装了python,可以在Terminal(CTRL+ALT+T)中输入:ls /usr/bin | grep python 进行查看. 如果想运行 ...
- 《浅析各类DDoS攻击放大技术》
原文链接:http://www.freebuf.com/articles/network/76021.html FreeBuf曾报道过,BT种子协议家族漏洞可用作反射分布式拒绝服务攻击(DRDoS a ...
- bzoj 3505 [Cqoi2014]数三角形(组合计数)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3505 [题意] 在n个格子中任选3点构成三角形的方案数. [思路] 任选3点-3点共线 ...
- 复习C语言
今天突然有感觉复习下C语言了,发现已经好久没有用过C编程了,话说最近都没有编过程序了都,趁现在还有点时间,好好学习下C了.话不多说上题目 请定义一个宏,比较两个数a.b的大小,不能使用大于.小于.if ...
- 《Genesis-3D开源游戏引擎--横版格斗游戏制作教程:简介及目录》(附上完整工程文件)
介绍:讲述如何使用Genesis-3D来制作一个横版格斗游戏,涉及如何制作连招系统,如何使用包围盒实现碰撞检测,软键盘的制作,场景切换,技能读表,简单怪物AI等等,并为您提供这个框架的全套资源,源码以 ...