[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 ...
随机推荐
- 前端每日实战:4# 视频演示如何用纯 CSS 创作一个金属光泽 3D 按钮特效
效果预览 按下右侧的"点击预览"按钮在当前页面预览,点击链接全屏预览. https://codepen.io/zhang-ou/full/MGeRRO 可交互视频教程 此视频是可以 ...
- Linux——如何将Red Hat Enterprise Linux 6的语言改为中文?
第一步,打开终端,输入su -,获取超级用户权限,输入密码. 第二步,输入cd /etc/sysconfig,进入设置目录. 第三步,输入vi i18n,进入到配置文件. 第四步,按 ‘i’键,进入编 ...
- Python入门的三大问题和三大谎言
Python广告,铺天盖地,小白们雾里看花,Python无限美好.作为会20几种语言(BASIC Foxbase/pro VB VC C C++ c# js typescript HTML Ardui ...
- python学习列表(Lists).基础二
列表(Lists) 序列是Python中最基本的数据结构,序列中的每个元素都分配一个数字,它的第一个索引是0第二个索引是1,依次类推. 列表是最常用的Python数据类型,它可以作为一个方括号内的逗号 ...
- 解决 unable to lock the administration directory (/var/lib/dpkg/) 问题
阿里开源镜像站提供了raspbian的软件包镜像,国内的用户可以选择改用阿里镜像站作为更新源. 但是在更换源之后,执行 sudo apt-get update && apt-get u ...
- php实现下载功能
<?php header("Content-type:text/html;charset=utf-8"); $file_name="1.text"; // ...
- Vue2.0 【第二季】第5节 Template制作模板
目录 Vue2.0 [第二季]第5节 Template制作模板 第5节 Template制作模板 一.直接写在选项里的模板 二.写在template标签里的模板 三.写在script标签里的模板 Vu ...
- [vue/require-v-for-key] Elements in iteration expect to have 'v-bind:key' directives.
使用VScode开发vue中,v-for在Eslint的规则检查下出现报错:如下Elements in iteration expect to have ‘v-bind:key’ directives ...
- js小数计算引起的精度误差问题
我记得刚开始学js的时候学到浮点有举例0.1+0.2 它的计算结果是: 0.1+0.20.30000000000000004 很神奇的一个计算,js是弱语言,在精度上没做处理: 我就自己定义了加减乘除 ...
- CSS的SVG学习
SVG 意为可缩放矢量图形(Scalable Vector Graphics). HTML三种方法导入svg文件: <html xmlns:svg="http://www.w3.org ...