[codeforces]Page Numbers <模拟>
描述:
«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.
题意基本就是思路
把所有数字去重排序,挨在一起的记录下来输出,没挨在一起单个输出就行
没什么难度
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<utility>
#include<stack>
#include<cstdlib>
#define ll long long
#define inf 0x3fffffff
using namespace std; int read(){
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
} void fre(){
freopen(" .in","r",stdin);
freopen(" .out","w",stdout);
} int n,flag,num1,num2;
int a[],barrel[],final[],tot; int main(){
while(scanf("%d",&a[n++])!=EOF)
char ch=getchar();
for(int i=;i<=n;i++){
if(barrel[a[i]]==){
final[tot]=a[i];tot++;
}barrel[a[i]]++;
}
sort(final,final+tot-);
num1=num2=final[];
flag=;
for(int i=;i<tot;i++){
if(final[i]==final[i-]+)num1=final[i];
else if(final[i]!=final[i-]+){
if(flag)printf(",");
flag=;
if(num1==num2)printf("%d",num1);
else printf("%d-%d",num2,num1);
num1=final[i];
num2=final[i];
}
}
return ;
}
[codeforces]Page Numbers <模拟>的更多相关文章
- ural 1150. Page Numbers
		
1150. Page Numbers Time limit: 1.0 secondMemory limit: 64 MB John Smith has decided to number the pa ...
 - Codeforces 34C-Page Numbers(set+vector+暴力乱搞)
		
C. Page Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
 - Educational Codeforces Round 2 A. Extract Numbers 模拟题
		
A. Extract Numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/600/pr ...
 - Codeforces 600A. Extract Numbers 模拟
		
A. Extract Numbers time limit per test: 2 seconds memory limit per test: 256 megabytes input: standa ...
 - Codeforces 631C. Report 模拟
		
C. Report time limit per test:2 seconds memory limit per test:256 megabytes input:standard input out ...
 - Codeforces 389B(十字模拟)
		
Fox and Cross Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Submi ...
 - codeforces 591B Rebranding (模拟)
		
Rebranding Problem Description The name of one small but proud corporation consists of n lowercase E ...
 - Codeforces 626B Cards(模拟+规律)
		
B. Cards time limit per test:2 seconds memory limit per test:256 megabytes input:standard input outp ...
 - Codeforces #55D-Beautiful numbers (数位dp)
		
D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ...
 
随机推荐
- 7-45 jmu-python-涨工资 (10 分)
			
输入一组工资数据,写入列表.对于小于5000的工资,涨1.5倍.并输出涨后的工资数据. 输入格式: 数据之间空格隔开 输出格式: 涨工资后的数据,空格隔开.尾部 不带空格. 输入样例: 3000 40 ...
 - Ios/Android h5 唤起本地APP
			
纠结两天(浏览器中唤起本地APP),一直找不到解决方案,今天总算基本搞定. ps:吐槽一下 魔窗那篇文章,为什么就不直接把js代码开源开源,混淆后的代码看得我好恼火 参考文章:魔窗解决方案.京东解决方 ...
 - 沪江iKcamp出品微信小程序教学共5章16小节汇总(含视频)
 - 备份Oracl数据库.bat
			
=========================== @echo off echo ================================================ echo Win ...
 - java-字节流练习(新手)
			
参考手册: 关键字: FileInputStream() Input是从硬盘到内存 FileOutputStream() 而output是从内存到硬盘,所以实现了复制粘贴. read() 调用方法读取 ...
 - Linux学习第六天
			
学习Linux环境下的挂载命令. 什么是挂载命令? 1.Windows下,mount挂载,就是给磁盘分区提供一个盘符(C,D,E,...).比如插入U盘后系统自动分配给了它I:盘符其实就是挂载,退优盘 ...
 - Natas29 Writeup(Perl命令注入、00截断、绕过过滤)
			
Natas29: 本关打开后,可以看到一个下拉列表,选择不同的内容,会得到不同的大量文本的页面. 观察url部分:http://natas29.natas.labs.overthewire.org/i ...
 - 当程序执行一条查询语句时,MySQL内部到底发生了什么? (说一下 MySQL 执行一条查询语句的内部执行过程?
			
先来个最基本的总结阐述,希望各位小伙伴认真的读一下,哈哈: 1)客户端(运行程序)先通过连接器连接到MySql服务器. 2)连接器通过数据库权限身份验证后,会先查询数据库缓存是否存在(之前执行过相同条 ...
 - Spring Cloud 系列之 Netflix Hystrix 服务监控
			
Actuator Hystrix 除了可以实现服务容错之外,还提供了近乎实时的监控功能,将服务执行结果和运行指标,请求数量成功数量等等这些状态通过 Actuator 进行收集,然后访问 /actuat ...
 - Web_jQuery
			
第1章: jQuery简介 为了简化 JavaScript 的开发,一些 JavsScript 库诞生了. JavaScript库封装了很多预定义的对象和实用函数,简化HTML与JavaScript之 ...