C. Page Numbers
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

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.

Input

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

Output the sequence in the required format.

Sample test(s)
input
1,2,3,1,1,2,6,6,2
output
1-3,6
input
3,2,1
output
1-3
input
30,20,10
output
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+暴力乱搞)的更多相关文章

  1. VIJOS1476 旅行规划(树形Dp + DFS暴力乱搞)

    题意: 给出一个树,树上每一条边的边权为 1,求树上所有最长链的点集并. 细节: 可能存在多条最长链!最长链!最长链!重要的事情说三遍 分析: 方法round 1:暴力乱搞Q A Q,边权为正-> ...

  2. Codeforces 1182D Complete Mirror 树的重心乱搞 / 树的直径 / 拓扑排序

    题意:给你一颗树,问这颗树是否存在一个根,使得对于任意两点,如果它们到根的距离相同,那么它们的度必须相等. 思路1:树的重心乱搞 根据样例发现,树的重心可能是答案,所以我们可以先判断一下树的重心可不可 ...

  3. [CSP-S模拟测试]:Cicada拿衣服(暴力+乱搞)

    题目传送门(内部题94) 输入格式 第一行两个整数$n,k$,代表衣服的数量和阈值. 接下来一行$n$个数,第$i$个数$a_i$表示每件衣服的愉悦值. 输出格式 输出一行$n$个数,第$i$个数为$ ...

  4. Codeforces #254 div1 B. DZY Loves FFT 暴力乱搞

    B. DZY Loves FFT 题目连接: http://codeforces.com/contest/444/problem/B Description DZY loves Fast Fourie ...

  5. Codeforces Gym 100203G Good elements 暴力乱搞

    原题链接:http://codeforces.com/gym/100203/attachments/download/1702/statements.pdf 题解 考虑暴力的复杂度是O(n^3),所以 ...

  6. Codeforces 245G Suggested Friends 暴力乱搞

    G. Suggested Friends time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  7. Codeforces 1513F - Swapping Problem(分类讨论+乱搞)

    Codeforces 题目传送门 & 洛谷题目传送门 简单题,难度 *2500 的 D2F,就当调节一下一模炸裂了的自闭的心情,稍微写写吧. 首先我看到这题的第一反应是分类讨论+数据结构,即枚 ...

  8. BZOJ 1491: [NOI2007]社交网络(Floyd+暴力乱搞)

    题面: https://www.lydsy.com/JudgeOnline/problem.php?id=1491 题解: 先看数据范围,n<=100..欸可以乱搞了 首先因为小学学过的乘法原理 ...

  9. CodeForces 509C Sums of Digits(贪心乱搞)题解

    题意:a是严格递增数列,bi是ai每一位的和,告诉你b1~bn,问你怎样搞才能让an最小 思路:让ai刚好大于ai-1弄出来的an最小.所以直接模拟贪心,如果当前位和前一个数的当前位一样并且后面还能生 ...

随机推荐

  1. C# Quartz 整理

    因项目需要,在C#中使用了定时程序.自然就使用了Quartz了 但是使用的时候,经过一段时间后,发现了两个重大问题,结果导致的是一样的,就是都导致了定时不会继续执行了. 第一个问题是,定时程序发布在I ...

  2. (10)ERStudio

     1.外键 https://jingyan.baidu.com/article/f79b7cb37e9d219144023ea6.html 第一个图标:Identifying Relationship ...

  3. 新疆大学ACM-ICPC程序设计竞赛五月月赛(同步赛)- 勤奋的杨老师(最长递增子序列)

    链接:https://www.nowcoder.com/acm/contest/116/C来源:牛客网 题目描述 杨老师认为他的学习能力曲线是一个拱形.勤奋的他根据时间的先后顺序罗列了一个学习清单,共 ...

  4. 微信小程序开发,上传wx.uploadFile 返回参数处理

    这真的是个坑,前端看了半天,说是字符串,让后台处理,后台说返回的是正确的,原来这个请求就是返回的string类型,见下图,无法取到code,需要前台自己转化. 以下为百度出来的参考: wx.reque ...

  5. C语言基础之指针

    1.指针的定义 格式:变量类型 *变量名; 1: // 定义了一个指针变量p 2: // 指针变量只能存储地址 3: // 指针就一个作用:能够根据一个地址值,访问对应的存储空间 4: // 指针变量 ...

  6. 使用Bundle在Activity间传递数据

    使用Bundle在Activity间传递数据 源Activity public class SourceActivty extends Activity { private Intent intent ...

  7. linux命令行翻页

    在linux上面执行命令,若命令太多屏幕显示不完,通过Shift+pageup/pageDown来查看. putty连接linux后执行就不存在这个问题.

  8. Winform打砖块游戏制作step by step第4节---小球移动

    一 引子 为了让更多的编程初学者,轻松愉快地掌握面向对象的思考方法,对象继承和多态的妙用,故推出此系列随笔,还望大家多多支持. 预备知识,无GDI画图基础的童鞋请先阅读一篇文章让你彻底弄懂WinFor ...

  9. ubifs & mtd

    前天晚上在写完另一篇总结之时,赵XX向我咨询了关于mtd 和ubifs的相关内容.而我在这方面只是略懂皮毛,所以向他许愿共同调查这个方面的知识.经过昨天一天的调查,最后感觉是有了一定的经验和基础了,所 ...

  10. apache 启动脚本加入系统服务列表

    第一步:cp /usr/local/apache2/bin/apachectl /etc/init.d/httpd第二步:vim /etc/init.d/httpd在第一行#!/bin/sh下增加两行 ...