URAL 1581. Teamwork

23 篇文章 0 订阅
16 篇文章 0 订阅

1581. Teamwork

Time limit: 1.0 second
Memory limit: 64 MB
Vasya and Petya are going to participate in a team olympiad in informatics. They have listened to the stories told by the gurus of olympiad programming and now they are aware that teamwork is of crucial importance for outstanding performance. Therefore they decided to develop their teamwork skills.
Vasya wrote a sequence of integers on a sheet of paper and started to read it to Petya number by number. For the sake of brevity he tells it in the following way: first he tells the quantity of consecutive identical numbers and then tells this number. For instance, the sequence “1 1 2 3 3 3 10 10” will be told by Vasya as “ two ones, one two, three threes, two tens”. Petya also wants to be concise, so he writes down the numbers pronounced by Vasya instead of the whole words. For the example above, Petya would write: “2 1 1 2 3 3 2 10”.
After some teamwork practice, Vasya and Petya also decided to develop programming skills and to write a computer program to convert Vasya's sequence to Petya's one.

Input

The first line contains an integer  N, which is the quantity of numbers written down by Vasya (1 ≤  N ≤ 1000) . The second line contains these numbers separated by spaces. All the numbers are positive integers not greater than 10.

Output

Output the numbers Petya would write down separated by space.

Sample

input output
8
1 1 2 3 3 3 10 10
2 1 1 2 3 3 2 10




题意:统计各个连续数字各有多少个,输出个数和数字。

解析:直接模拟即可。



AC代码:

#include <cstdio>

int main(){
    #ifdef sxk
        freopen("in.txt", "r", stdin);
    #endif //sxk

    int n, a, b, cnt;
    while(scanf("%d", &n)==1){
        cnt = 0;
        for(int i=0; i<n; i++){
            scanf("%d", &a);
            if(i && a != b){
                printf("%d %d ", cnt, b);
                cnt = 0;
            }
            b = a;
            cnt ++;
            if(i == n-1) printf("%d %d\n", cnt, b);
        }
    }
    return 0;
}


PS:模拟还真是不容易呀。。。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值