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. Android集成高德地图如何自定义marker

    高德地图自定义Marker 高德地图默认的marker样式是这种 一般的修改样式是通过icon接口来调整 MarkerOptions markerOptions = new MarkerOptions ...

  2. AC日记——[HNOI2008]水平可见直线 bzoj 1007

    1007 思路: 维护一个下凸壳: 用单调栈来维护这玩意儿: 先将斜率排序: 然后判断栈顶元素和当前元素的交点x是否小于栈顶元素和栈顶上一个元素的交点x: 注意: 人神共愤的精度问题和输出空格问题: ...

  3. Strobogrammatic Number -- LeetCode

    A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside ...

  4. MySQL类型转换 使用CAST将varchar转换成int类型排序

    --使用CAST将varchar转换成int类型排序 select distinct(zone_id) from guild_rank_info order by CAST(zone_id as SI ...

  5. SQL SERVER 内存学习系列

    http://www.cnblogs.com/double-K/p/5049417.html http://blog.sina.com.cn/s/blog_5deb2f5301014wti.html ...

  6. 彻底理解Javascript 中的 Promise(-------------------------------***---------------------------------)

    ES6原生提供了 Promise 对象. 到底是何方妖怪呢?打出来看看: 所谓 Promise,就是一个对象,用来传递异步操作的消息.它代表了某个未来才会知道结果的事件(通常是一个异步操作),并且这个 ...

  7. Android ToolBar 使用完全解析

    ToolBar简介 ToolBar是Android 5.0推出的一个新的导航控件用于取代之前的ActionBar,由于其高度的可定制性.灵活性.具有Material Design风格等优点,越来越多的 ...

  8. sqlserver中常用的四个选项(NOCOUNT/ANSI_NULLS/QUOTED_IDENTIFIER/ XACT_ABORT)

    1 NOCOUNT选项 当 SET NOCOUNT 为 ON 时,不返回计数.当 SET NOCOUNT 为 OFF 时,返回计数. eg: if object_id(N'table_test',N' ...

  9. ylbtech-KeFuYunWei(服务运维考核系统)-数据库设计

    ylbtech-DatabaseDesgin:ylbtech-KeFuYunWei(服务运维考核系统)-数据库设计 DatabaseName:KEFUYUNWEI Model:Admin 用户后台管理 ...

  10. spring boot 缺点优点?

    作者:八面山人链接:https://www.zhihu.com/question/39483566/answer/246333825来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请 ...