描述:

«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 <模拟>的更多相关文章

  1. ural 1150. Page Numbers

    1150. Page Numbers Time limit: 1.0 secondMemory limit: 64 MB John Smith has decided to number the pa ...

  2. Codeforces 34C-Page Numbers(set+vector+暴力乱搞)

    C. Page Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  3. Educational Codeforces Round 2 A. Extract Numbers 模拟题

    A. Extract Numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/600/pr ...

  4. Codeforces 600A. Extract Numbers 模拟

    A. Extract Numbers time limit per test: 2 seconds memory limit per test: 256 megabytes input: standa ...

  5. Codeforces 631C. Report 模拟

    C. Report time limit per test:2 seconds memory limit per test:256 megabytes input:standard input out ...

  6. Codeforces 389B(十字模拟)

    Fox and Cross Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submi ...

  7. codeforces 591B Rebranding (模拟)

    Rebranding Problem Description The name of one small but proud corporation consists of n lowercase E ...

  8. Codeforces 626B Cards(模拟+规律)

    B. Cards time limit per test:2 seconds memory limit per test:256 megabytes input:standard input outp ...

  9. Codeforces #55D-Beautiful numbers (数位dp)

    D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ...

随机推荐

  1. MySQL集群MGR架构for单主模式

    本文转载自: https://www.93bok.com MGR简介 MySQL Group Replication(简称MGR)是MySQL官方于2016年12月推出的一个全新的高可用与高扩展的解决 ...

  2. mysql从5.5升级到5.7遇到的坑

    在安装mysql5.7时很顺利安装完成,但在启动项目时报错: [Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clau ...

  3. 【11】openlayers 地图交互

    地图交互interaction 关于map的方法: //添加地图交互 map.addInteraction(interaction) //删除地图交互 map.removeInteraction(in ...

  4. Simulink仿真入门到精通(十三) Simulink创建自定义库

    当用户自定义了一系列模块之后,可以自定义模块库将同类自定义模块显示到Simulink Browser中,作为库模块方便地拖曳到新建模型中. 建立这样的自定义库需要3个条件: 建立library的mdl ...

  5. Linux启动nginx时报错nginx: [emerg] getpwnam("nginx") failed

    编译时指定了用户而没有创建用户导致报错 解决: 查看你添加的用户是什么, [root@localhost nginx]# sbin/nginx -Vnginx version: nginx/1.10. ...

  6. 谈谈一些逻辑相同,性能差异却很大的sql

    总结写在前面: 1. 本篇讲述了三个例子,其本质都是揭示了若对索引字段做函数操作,可能会破坏索引值的有序性,由此优化器就决定放弃走树搜索功能. 2. 由第1点提供了一个优化思路,即我们能否避免或转化s ...

  7. 如何在vue中修改动态标签中的样式和修改组件库样式

    vue中修改动态标签中的样式和修改组件库样式 因为vue中的标签在渲染的时候,都会给标签加上id 所以你想在<style lang="scss" scoped>直接修改 ...

  8. 小程序中内容审核功能的使用(后台使用thinkPHP5.1)

    本文包含文本和图片的检测 //接收要检测的文本内容并调用检测方法 public function textCheck(Request $request){ //内容安全识别 $data['conten ...

  9. 【Weiss】【第03章】练习3.21:单数组模拟双栈

    [练习3.21] 编写仅用一个数组而实现两个栈的例程.除非数组的每一个单元都被使用,否则栈例程不能有溢出声明. Answer: 很简单,一个栈从数组头起,一个栈从数组尾起,分别保留左右栈头索引. 如l ...

  10. Analysis of endogenous peptides released from osteoarthritic cartilage unravels novel pathogenic markers (解读人:李琼)

    文献名:Analysis of endogenous peptides released from osteoarthritic cartilage unravels novel pathogenic ...