Kattis -Bus Numbers
Bus Numbers
Your favourite public transport company LS (we cannot use their real name here, so we permuted the letters) wants to change signs on all bus stops. Some bus stops have quite a few buses that stop there and listing all the buses takes space. However, if for example buses 141, 142, 143 stop there, we can write 141–143 instead and this saves space. Note that just for two buses this does not save space.
You are given a list of buses that stop at a bus stop. What is the shortest representation of this list?
Input
The first line of the input contains one integer N,1≤N≤1000N,1≤N≤1000, the number of buses that stop at a bus stop. Then next line contains a list of NN space separated integers between 1 and 10001000, which denote the bus numbers. All numbers are distinct.
Output
Print the shortest representation of the list of bus numbers. Use the format as in the example, separate numbers with single spaces and output them in sorted order.
| Sample Input 1 | Sample Output 1 |
|---|---|
6 |
141-143 174 175 180 |
题意
将给出的数字按照升序排好,然后是连续的就连起来直接输出
代码
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
#pragma warning(disable:4996);
int a[],n;
int main() {
while (~scanf("%d", &n))
{
for (int i = ; i < n; i++)
{
scanf("%d", &a[i]);
}
sort(a, a + n);
int key = ;
printf("%d", a[]);
if (a[] + == a[])key++;
for (int i = ; i < n; i++)
{
if (key == && a[i] + == a[i + ])
{
printf(" %d", a[i]);
key++;
}
else if (key &&a[i] + == a[i + ])
{
key++;
continue;
}
else if (a[i + ]!= a[i] + )
{
if (key>)
{
key = ;
printf("-%d", a[i]);
}
else
{
key = ;
printf(" %d", a[i]);
}
}
}puts("");
}
return ;
}
Kattis -Bus Numbers的更多相关文章
- usb驱动开发15之设备生命线
总算是进入了HCD的片儿区,既然来到一个片区,怎么都要去拜会一下山头几个大哥吧.,先回忆一些我们怎么到这里的?给你列举一个调用函数过程usb_control_msg->usb_internal_ ...
- grub paramiter & menu.list
在Linux中,给kernel传递参数以控制其行为总共有三种方法: 1.build kernel之时的各个configuration选项. 2.当kernel启动之时,可以参数在kernel被GRUB ...
- Linux+I2C总线分析(主要是probe的方式)
Linux I2C 总线浅析 ㈠ Overview Linux的I2C体系结构分为3个组成部分: ·I2C核心: I2C核心提供了I2C总线驱动和设备驱动的注册.注销方法,I2C通信方法(即“algo ...
- Linux I2C设备驱动编写(二)
在(一)中简述了Linux I2C子系统的三个主要成员i2c_adapter.i2c_driver.i2c_client.三者的关系也在上一节进行了描述.应该已经算是对Linux I2C子系统有了初步 ...
- 【转】Linux I2C设备驱动编写(二)
原文网址:http://www.cnblogs.com/biglucky/p/4059582.html 在(一)中简述了Linux I2C子系统的三个主要成员i2c_adapter.i2c_drive ...
- i2c sub system __i2c_board_list/klist_devices/klist_drivers
i2c_devinfo全局链表: __i2c_board_list 用来挂接 i2c_board_info,这个信息用来生成 i2c_client i2c_client 链表: i2c_bus_typ ...
- linux驱动工程面试必问知识点
linux内核原理面试必问(由易到难) 简单型 1:linux中内核空间及用户空间的区别?用户空间与内核通信方式有哪些? 2:linux中内存划分及如何使用?虚拟地址及物理地址的概念及彼此之间的转化, ...
- i2c设备驱动注册
Linux I2C设备驱动编写(二) 原创 2014年03月16日 23:26:50 在(一)中简述了Linux I2C子系统的三个主要成员i2c_adapter.i2c_driver.i2c ...
- Linux驱动:I2C驱动编写要点
继续上一篇博文没讲完的内容“针对 RepStart 型i2c设备的驱动模型”,其中涉及的内容有:i2c_client 的注册.i2c_driver 的注册.驱动程序的编写. 一.i2c 设备的注册分析 ...
随机推荐
- windows server 2003断开远程之后自动注销用户
windows server 2003断开远程之后自动注销用户 2011-07-30 09:42:52 我来说两句 收藏 我要投稿 最近一台服务器老是断开远程之后过没多久就自动 ...
- vs10创建sqlclr部署失败
将项目解决方案改为3.5,调试OK:
- MVC之验证
MVC之验证 有时候我觉得,很多人将一个具体的技术细节写的那么复杂,我觉得没有必要,搞得很多人一头雾水的,你能教会别人用就成了,具体的细节可以去查MSDN什么的,套用爱因斯坦的名言:能在网上查到的就不 ...
- MVC 控制器激活
MVC 控制器激活 ASP.NET MVC 控制器激活(三) 前言 在上个篇幅中说到从控制器工厂的GetControllerInstance()方法来执行控制器的注入,本篇要讲是在GetControl ...
- WCF订阅替换轮训
使用WCF订阅替换轮训 之前因为某些特定岗位的人不知道是不方便还是什么的原因,所以随便做了个独立于所有系统之外的邮件审批服务,功能是那些人在邮件里给待审批单据发个“同意”就自动审批通过,大致分为3部分 ...
- Effective C++(18) 让接口更容易被正确使用,不易被误用
问题聚焦: 从这个条款开始,我们把注意力转移到软件设计和声明上来,具体的说就是,C++接口的设计和声明. 所谓软件设计,就是以一般习惯的构想开始,演变成细节的实现,最终开发针对性的特殊 ...
- css,js工具篇
4. web前端开发分享-css,js工具篇 web前端开发乃及其它的相关开发,推荐sublime text, webstorm(jetbrains公司系列产品)这两个的原因在于,有个技术叫emm ...
- Linq无聊练习系列4--join练习
/**************join 练习*******************/ //对于1对多关系 var list =from c in ctx.T ...
- Web API 2
Asp.Net Web API 2 官网菜鸟学习系列导航[持续更新中] 前言 本来一直参见于微软官网进行学习的, 官网网址http://www.asp.net/web-api.出于自己想锻炼一下学 ...
- JS自动刷新页面一次
<script type="text/javascript"> //刷新页面 if(location.href.indexOf("refresh=1" ...