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最小.所以直接模拟贪心,如果当前位和前一个数的当前位一样并且后面还能生 ...
随机推荐
- Wannafly挑战赛22 A-计数器(gcd,裴蜀定理)
原题地址 题目描述 有一个计数器,计数器的初始值为0,每次操作你可以把计数器的值加上a1,a2,...,an中的任意一个整数,操作次数不限(可以为0次),问计数器的值对m取模后有几种可能. 输入描述: ...
- 浅析 Node.js 单线程模型
总结笔记:对于每个用户请求,由主线程接收并存放于一个事件队列中(不做任何处理),当无请求发生时,即主线程空闲,主线程开始循环处理事件队列中的任务: 对于非阻塞JS程序: 1.若某事件需要I/O操作,则 ...
- luogu P1122 最大子树和
题目描述 小明对数学饱有兴趣,并且是个勤奋好学的学生,总是在课后留在教室向老师请教一些问题.一天他早晨骑车去上课,路上见到一个老伯正在修剪花花草草,顿时想到了一个有关修剪花卉的问题.于是当日课后,小明 ...
- Loj #6019. 「from CommonAnts」寻找 LCM
给个链接:https://loj.ac/problem/6019 还是一道扩展卢卡斯+中国剩余定理....就当练练手 但是这题怎么这么卡常呢????!!!!! 在LOJ上死也过不去 (为什么要加那么多 ...
- Java类的定义及其实例化
如果你不了解类和对象的概念,请猛击这里:Java类和对象的概念 类必须先定义才能使用.类是创建对象的模板,创建对象也叫类的实例化. 下面通过一个简单的例子来理解Java中类的定义: public cl ...
- thinkphp3.0增加setInc、setDec方法
thinkphp3.0增加setInc.setDec方法 thinkphp3.0增加setInc.setDec方法,今天查看thinkphp2.0的方法setInc.setDec时是这样写的: 而对于 ...
- 删除VisualStudio 2013中的 "send Feedback" 按钮
在VisualStudio 2013中,在标题栏中增加了一个 "send Feedback" 按钮,用于给微软发送Bug和回馈(或者一个哭脸和笑脸).这个按钮对于开发来说基本上没用 ...
- 【SQL】用Sql Server自动生产html格式的数据字典
原文:[SQL]用Sql Server自动生产html格式的数据字典 本文软件环境:Sql Server 2008. 1.打开sql server管理器,给选定的表添加描述信息,给指定的字段添加描述信 ...
- linux mysql cluser集群
管理节点的安装与启动 config.init内容如下 [NDBD DEFAULT] NoOfReplicas=1 #定义在Cluster环境中相同数据的份数,最大为4 [NDB_MGMD] #设置管理 ...
- 【启动】Windows上启动图形化软件,报错: 无法启动此程序,因为计算机中丢失api-ms-win-crt-runtime-1-1-0.dll
今天在安装了jetbrains官网上的ToolBox软件后,没有办法启动起来,报错如下: 无法启动此程序,因为计算机中丢失api-ms-win-crt-runtime-1-1-0.dll 尝试重新安装 ...