Codeforces 34C-Page Numbers(set+vector+暴力乱搞)
2 seconds
256 megabytes
standard input
standard output
«Bersoft» company is working on a new version of its most popular text editor — Bord 2010. Bord, like many other text editors, should be able to print out multipage documents. A user keys a sequence of the document page numbers that he wants to print out (separates
them with a comma, without spaces).
Your task is to write a part of the program, responsible for «standardization» of this sequence. Your program gets the sequence, keyed by the user, as input. The program should output this sequence in format l1-r1,l2-r2,...,lk-rk,
where ri + 1 < li + 1 for
all i from 1 to k - 1,
and li ≤ ri.
The new sequence should contain all the page numbers, keyed by the user, and nothing else. If some page number appears in the input sequence several times, its appearances, starting from the second one, should be ignored. If for some element i from
the new sequence li = ri,
this element should be output as li,
and not as «li - li».
For example, sequence 1,2,3,1,1,2,6,6,2 should be output as 1-3,6.
The only line contains the sequence, keyed by the user. The sequence contains at least one and at most 100 positive integer numbers. It's guaranteed, that this sequence consists of positive integer numbers, not exceeding 1000, separated with a comma, doesn't
contain any other characters, apart from digits and commas, can't end with a comma, and the numbers don't contain leading zeroes. Also it doesn't start with a comma or contain more than one comma in a row.
Output the sequence in the required format.
1,2,3,1,1,2,6,6,2
1-3,6
3,2,1
1-3
30,20,10
10,20,30
题意有点坑。 。看了半小时才看懂
题意:给一串数字,排序去重后,连续的要合并,比方 1,2,3 变成1-3。 而不连续的,比方1,2,3,6, 6要单独打印。即 1-3。6
输入不好弄。。 然后我直接串输入又瞎处理了一番。。后来去重+排序是直接扔到set里面撸一遍然后在塞到vector里了QAQ
在然后就是依据题意乱搞了
代码写挫了。。
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cctype>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#define ll long long
#define maxn 116
#define pp pair<int,int>
#define INF 0x3f3f3f3f
#define max(x,y) ( ((x) > (y)) ? (x) : (y) )
#define min(x,y) ( ((x) > (y)) ? (y) : (x) )
using namespace std;
char str[10100];
int main()
{ while(~scanf("%s",str)){
set <int> s;int tem;char sb[6];
for(int i=0;i<=strlen(str);i++)
{
if(str[i]==','||str[i]=='\0')
{
int p=0,q=i;
while((--q)>=0&&str[q]!=',')sb[p++]=str[q];
sb[p]='\0';strrev(sb);sscanf(sb,"%d",&tem);
s.insert(tem);
}
}
vector <int> a(s.begin(),s.end());
int ansx[1010],ansy[1010],p=0;
for(int i=0;i<a.size()-1;i++)
{
int pos=i;
while(i+1<a.size()&&a[i]+1==a[i+1])
i++;
ansx[p]=a[pos];ansy[p++]=a[i];
}
if(ansy[p-1]!=a[a.size()-1])
{
ansx[p]=a[a.size()-1];
ansy[p++]=a[a.size()-1];
}
for(int i=0;i<p;i++)
{
if(i!=p-1)
{
if(ansx[i]==ansy[i])
printf("%d,",ansx[i]);
else
printf("%d-%d,",ansx[i],ansy[i]);
}
else
{
if(ansx[i]==ansy[i])
printf("%d\n",ansx[i]);
else
printf("%d-%d\n",ansx[i],ansy[i]);
}
}
}
return 0;
}
Codeforces 34C-Page Numbers(set+vector+暴力乱搞)的更多相关文章
- VIJOS1476 旅行规划(树形Dp + DFS暴力乱搞)
题意: 给出一个树,树上每一条边的边权为 1,求树上所有最长链的点集并. 细节: 可能存在多条最长链!最长链!最长链!重要的事情说三遍 分析: 方法round 1:暴力乱搞Q A Q,边权为正-> ...
- Codeforces 1182D Complete Mirror 树的重心乱搞 / 树的直径 / 拓扑排序
题意:给你一颗树,问这颗树是否存在一个根,使得对于任意两点,如果它们到根的距离相同,那么它们的度必须相等. 思路1:树的重心乱搞 根据样例发现,树的重心可能是答案,所以我们可以先判断一下树的重心可不可 ...
- [CSP-S模拟测试]:Cicada拿衣服(暴力+乱搞)
题目传送门(内部题94) 输入格式 第一行两个整数$n,k$,代表衣服的数量和阈值. 接下来一行$n$个数,第$i$个数$a_i$表示每件衣服的愉悦值. 输出格式 输出一行$n$个数,第$i$个数为$ ...
- Codeforces #254 div1 B. DZY Loves FFT 暴力乱搞
B. DZY Loves FFT 题目连接: http://codeforces.com/contest/444/problem/B Description DZY loves Fast Fourie ...
- Codeforces Gym 100203G Good elements 暴力乱搞
原题链接:http://codeforces.com/gym/100203/attachments/download/1702/statements.pdf 题解 考虑暴力的复杂度是O(n^3),所以 ...
- Codeforces 245G Suggested Friends 暴力乱搞
G. Suggested Friends time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- Codeforces 1513F - Swapping Problem(分类讨论+乱搞)
Codeforces 题目传送门 & 洛谷题目传送门 简单题,难度 *2500 的 D2F,就当调节一下一模炸裂了的自闭的心情,稍微写写吧. 首先我看到这题的第一反应是分类讨论+数据结构,即枚 ...
- BZOJ 1491: [NOI2007]社交网络(Floyd+暴力乱搞)
题面: https://www.lydsy.com/JudgeOnline/problem.php?id=1491 题解: 先看数据范围,n<=100..欸可以乱搞了 首先因为小学学过的乘法原理 ...
- CodeForces 509C Sums of Digits(贪心乱搞)题解
题意:a是严格递增数列,bi是ai每一位的和,告诉你b1~bn,问你怎样搞才能让an最小 思路:让ai刚好大于ai-1弄出来的an最小.所以直接模拟贪心,如果当前位和前一个数的当前位一样并且后面还能生 ...
随机推荐
- maven构建的模块化的JavaWeb工程
最近对maven构建的模块化的JavaWeb工程,比较感兴趣,所以自己就想从头弄一个出来,在此做一个记录,供以后学习. 前置条件:电脑上有eclipse(或者myeclipse,记事本也可以,那样就得 ...
- Python的Web编程[2] -> WebService技术[0] -> 利用 Python 调用 WebService 接口
WebService技术 / WebService Technology 1 关于webservice / Constants WebService是一种跨编程语言和跨操作系统平台的远程调用技术. W ...
- csu1808
csu1808 题意 n 个点间有 m 条地铁,每条地铁可能属于不同的线路,每条地铁有权值即通过时花费的时间,如果乘坐第 i 条地铁来到地铁站 s,再乘坐第 j 条地铁离开,需要花费额外的时间 \(| ...
- IE8兼容性问题
由于业务的需要,我们竟然还要支持IE8,听着就让人很心酸呀.不过在进行适配的过程中,会发现还是有一定规律的,基本上帮相关问题改了,页面也就能正常显示了.下面就总结下对IE8适配过程中所进行的修改. 1 ...
- JavaScrip book
1.<JavaScript: The Good Parts>中文版:<JavaScript语言精粹>2.<Professional JavaScript for Web ...
- Mac eclipse安装SVN javaHL not available的解决方法
在Mac下安装Eclipse插件svnEclipse插件后,每次打开Eclipse都会弹出如下弹出框: 提示你本机缺少JavaHL Library. 选择Eclipse→偏好设置(preference ...
- devops流程
学习资源: https://www.youtube.com/watch?v=JBtWxj9l7zM&list=PLoYCgNOIyGAAzevEST2qm2Xbe3aeLFvLc&t= ...
- ECShop后台管理菜单修改
ECShop中,和后台菜单相关的文件有两个: ·菜单项:admin\includes\inc_menu.php·菜单文本:languages\zh_cn\admin\common.php 所以,要修改 ...
- 转:MyBatis学习总结(Mybatis总结精华文章)
http://www.cnblogs.com/xdp-gacl/tag/MyBatis%E5%AD%A6%E4%B9%A0%E6%80%BB%E7%BB%93/ 当前标签: MyBatis学习总结 ...
- 【Android高级】NDK/JNI编程技术基础介绍
作为一个Andoird的Java程序猿,会受到Java语言的局限.由于作为一面门向对象的语言不能像C/C++那样轻易调用与硬件有关的操作.因此JNI就搭建了这样一个桥梁,使Java和C/C++语言之间 ...