Codeforces 600A. 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 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".
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 words are 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", "".
题意:有一个仅包含 '.' , ',' , ';' 大小写字母,数字的字符串s (1 ≤ |s| ≤ 105)。 ',' 和 ';'为分隔符。a字符串是不为0开头的纯数字,其余的均为b字符串。空的也为b中的。具体的看样例和note
思路:暴力一遍来判断,但是在字符串的前面和后面均加一个',',这样可以更加方便判断特殊情况。
#include<bits/stdc++.h>
using namespace std;
char s[];
char a[],b[];
int count1[],count2[];
int main()
{
cin>>s;
int i,j,n=,m=,sign,flag,len=strlen(s);
sign=-;
s[len]=';';
memset(count1,,sizeof(count1));
memset(count2,,sizeof(count2));
for(i=; i<=len; i++)
{
if(s[i]==','||s[i]==';')
{ if(sign+==i)
{
b[m++]='*';
count2[m-]=;
}
else
{
flag=;
if(s[sign+]==''&&(sign+==i)) flag=;
else
{
if(s[sign+]<=''&&s[sign+]>='') flag=;
if(flag==)
{
for(j=sign+; j<i; j++)
{
if(!(s[j]<=''&&s[j]>='')) break;
}
if(j<i) flag=;
else flag=;
}
}
if(flag==)
{
for(j=sign+; j<i; j++)
b[m++]=s[j];
count2[m-]=;
}
else
{
for(j=sign+; j<i; j++)
a[n++]=s[j];
count1[n-]=;
}
}
sign=i;
}
}
if(n==) cout<<"-"<<endl;
else
{
cout<<"\"";
for(i=; i<n; i++)
{
cout<<a[i];
if(count1[i]==&&(i<n-)) cout<<",";
}
cout<<"\""<<endl;
} if(m==) cout<<"-"<<endl;
else
{
cout<<"\"";
for(i=; i<m; i++)
{
if(b[i]=='*');
else cout<<b[i];
if(count2[i]==&&(i<m-)) cout<<",";
}
cout<<"\""<<endl;
}
return ;
}
Codeforces 600A. Extract Numbers 模拟的更多相关文章
- codeforces 600A Extract Numbers
模拟题,意思是一个字符串,单词直接用','或';'来分割,可以为空,把不含前导0的整数和其他单词分别放入A和B.按照一定格式输出. 没有用stl的习惯.维护两个下标i,j,表示开区间(i,j),两段补 ...
- Educational Codeforces Round 2 A. Extract Numbers 模拟题
A. Extract Numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/600/pr ...
- codeforce 600A - Extract Numbers
学习string #include <bits/stdc++.h> #define eps 1e-8 #define M_PI 3.141592653589793 ; using name ...
- [模拟]Educational Codeforces Round 2A Extract Numbers
Extract Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- CodeForces 55D "Beautiful numbers"(数位DP+离散化处理)
传送门 参考资料: [1]:CodeForces 55D Beautiful numbers(数位dp&&离散化) 我的理解: 起初,我先定义一个三维数组 dp[ i ][ j ][ ...
- Codeforces 878 E. Numbers on the blackboard
Codeforces 878 E. Numbers on the blackboard 解题思路 有一种最优策略是每次选择最后面一个大于等于 \(0\) 的元素进行合并,这样做完以后相当于给这个元素乘 ...
- Codeforces 55D. Beautiful numbers(数位DP,离散化)
Codeforces 55D. Beautiful numbers 题意 求[L,R]区间内有多少个数满足:该数能被其每一位数字都整除(如12,24,15等). 思路 一开始以为是数位DP的水题,觉得 ...
- [codeforces]Page Numbers <模拟>
描述: «Bersoft» company is working on a new version of its most popular text editor — Bord 2010. Bord, ...
- Educational Codeforces Round 2 A. Extract Numbers
打开题目链接 题意:输入一个字符串,用,或:分隔输出字符串和整数(不含前导0和浮点数) ACcode: #include <iostream> #include <cstdio> ...
随机推荐
- webpack(5)--Resolve
Resolve webpack在启动后会从配置的入口模块触发找出所有依赖的模块,Resolve配置webpack如何寻找模块对应的文件.webpack内置JavaScript模块化语法解析功能,默认会 ...
- PHP写日志公共类
Txl_Log.php <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * * * ...
- foreach的使用
//foreach循环语句,常用来遍历数组,一般有两种使用方法:不取下标,取下标 //不取下表 foreach(数组 as 值) { //执行的程序 echo 值; } //取下标 foreach(数 ...
- 折腾了好久,thinkphp5打开提示加载failed to open stream: No such file or directory in think start.php
GIT上下载的THINKPHP5记得先 composer update 我就是没update ,折腾了1个小时,才想起来这个事 thinkphp5默认首页打开空白 打开报错提示 提示thinkphp ...
- CentOS Apache配置详解
要想在linux上实现网页服务器(www)需要Apache这个服务器软件,不过Apache仅能提供最基本的静态网站数据而已,想要实现动态网站的话,最好还是要PHP与MySQL的支持,所以下面我们将会以 ...
- java Export Excel POI 转
最终选择用POI成功导出excel.总之很有用. http://www.cnblogs.com/xwdreamer/archive/2011/07/20/2296975.html http://poi ...
- FindWindow 查找窗口
Declare Function SendMessage Lib "user32" Alias "SendMessageA" _ (ByVal hwnd As ...
- GPO配置时的注意事项
当两个组策略冲突时: 1.如在同一层OU,后生效的组策略有效,优先级高.在组织单元的'链接的组策略对象'中标明了组策略的先后应用次序,其中下面的组策略先应用,上面的组策略后应用,即上面的组策略优先级高 ...
- ABAP-关于COMMIT WORK 和COMMIT WORK AND WAIT
转载:https://blog.csdn.net/champaignwolf/article/details/6925019 首先说明一点:更新是异步的,更新是由SAP中UPD1和UPD2两个进程执行 ...
- String类的intern()方法
0.引言 什么都先不说,先看下面这个引入的例子: String str1 = new String("SEU")+ new String("Calvin"); ...