URAL 1581. Teamwork

Source: Internet
Author: User

1581. Teamwork
Time limit:1.0 Second
Memory limit:64 MB
Vasya and Petya is going to participate in a Team Olympiad in informatics. They has listened to the stories told by the Gurus of Olympiad programming and now they be aware that teamwork is of Cru cial 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 the this number. For instance, the sequence "1 1 2 3 3 3 Ten" would be told by Vasya as " ones, one, three threes, tens”. Petya also wants to is 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 T o convert vasya ' s sequence to Petya ' s one. Inputthe 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 is positive integers not greater than 10.OutputOutput the numbers Petya would write down separated by spa Ce. Sample
input Output
81 1 2 3 3 3 10 10
2 1 1 2 3 3 2 10




Test instructions: Statistics of the number of each successive numbers, output number and number.

Analysis: Direct simulation can be.



AC Code:

#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: Simulation is really not easy ...


URAL 1581. Teamwork

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.