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