码迷,mamicode.com
首页 > 其他好文 > 详细

URAL 1581. Teamwork

时间:2015-03-07 14:16:40      阅读:129      评论:0      收藏: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:模拟还真是不容易呀。。。


URAL 1581. Teamwork

标签:

原文地址:http://blog.csdn.net/u013446688/article/details/44115153

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!