[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 ...
随机推荐
- DSO 运行 —— dso_ros + Android 手机摄像头
转载请注明出处,谢谢 原创作者:Mingrui 原创链接:https://www.cnblogs.com/MingruiYu/p/12425855.html 本文要点: dso 配置安装 dso 离线 ...
- Py基础之函数
'''函数是指一类同类事物的抽象,而且这种抽象可以拓展,并且可以用在同一类事物上'''print (abs(-100),abs(100)) #abs函数是python内置的函数,可以用来求绝对值#pr ...
- Angular 1 深度解析:脏数据检查与 angular 性能优化
TL;DR 脏检查是一种模型到视图的数据映射机制,由 $apply 或 $digest 触发. 脏检查的范围是整个页面,不受区域或组件划分影响 使用尽量简单的绑定表达式提升脏检查执行速度 尽量减少页面 ...
- 一个轻量级的基于 .NET Core 的 ORM 框架 HSQL
HSQL 是一种轻量级的基于 .NET Core 的数据库对象关系映射「ORM」框架 HSQL 是一种可以使用非常简单且高效的方式进行数据库操作的一种框架,通过简单的语法,使数据库操作不再成为难事.目 ...
- JZOJ 1349. 最大公约数 (Standard IO)
1349. 最大公约数 (Standard IO) Time Limits: 1000 ms Memory Limits: 65536 KB Description 小菜的妹妹小诗就要读小学了!正所谓 ...
- DirectX11--深入理解Effects11、使用着色器反射机制(Shader Reflection)实现一个复杂Effects框架
前言 如果之前你是跟随本教程系列学习的话,应该能够初步了解Effects11(现FX11)的实现机制,并且可以编写一个简易的特效管理框架,但是随着特效种类的增多,要管理的着色器.资源等也随之变多.如果 ...
- linux最常用命令记录(一)
一.vim个人最常用设置: vim .vimrc 然后添加以下内容 set nu set tabstop=4 set encoding=utf-8 二.查看磁盘空间相关命令 1.df -h 查看硬 ...
- 复制图片链接和标题生成Markdown文本
写Markdown的时候常常会需要复制图片链接和标题以插入图片,不借助其他工具的话,一般需要先在Markdown文件中输入插入图片的格式,然后在浏览器中复制图片链接和标题将其依次粘贴到Markdown ...
- 简说Python之图形初体验
针对孩子,最容易引起小孩的感官认知的就是图形.因此,系统运用图形编程,可以更好地让孩子喜欢上编程. turtle叫做,Turtle graphics.是python第三方的画图模块工具.可以通过imp ...
- vue基础回顾 router
vue-router 1. 底层原理 hash 或者h5 histroy(有兼容性) 2. 使用的时候Vue需要引入VueRouter Vue.use(VueRouter) //VueRouter 底 ...