Codeforce 825A - Binary Protocol

 

Polycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm:

  • Each digit is represented with number of '1' characters equal to the value of that digit (for 0 it is zero ones).
  • Digits are written one by one in order corresponding to number and separated by single '0' character.

Though Polycarp learnt how to encode the numbers, he has no idea how to decode them back. Help him calculate the decoded number.

Input

The first line contains one integer number n (1 ≤ n ≤ 89) — length of the string s.

The second line contains string s — sequence of '0' and '1' characters, number in its encoded format. It is guaranteed that the number corresponding to the string is positive and doesn't exceed 109. The string always starts with '1'.

Output

Print the decoded number.

Examples
input
3
111
output
3
input
9
110011101
output
2031

题解:水水
 1 #include <iostream>
 2 #include <algorithm>
 3 #include <cstring>
 4 #include <cstdio>
 5 #include <vector>
 6 #include <cstdlib>
 7 #include <iomanip>
 8 #include <cmath>
 9 #include <ctime>
10 #include <map>
11 #include <set>
12 using namespace std;
13 #define lowbit(x) (x&(-x))
14 #define max(x,y) (x>y?x:y)
15 #define min(x,y) (x<y?x:y)
16 #define MAX 100000000000000000
17 #define MOD 1000000007
18 #define pi acos(-1.0)
19 #define ei exp(1)
20 #define PI 3.141592653589793238462
21 #define INF 0x3f3f3f3f3f
22 #define mem(a) (memset(a,0,sizeof(a)))
23 typedef long long ll;
24 const int N=1005;
25 const int mod=1e9+7;
26 int main()
27 {
28     int n,num=0;
29     char str[91];
30     cin >> n;
31     for(int i=0;i<n;i++)
32         cin >> str[i];
33     for(int i=0;i<n;i++){
34         if(str[i]=='1')
35             num++;
36         else{
37             cout << num;
38             num=0;
39         }
40     }
41     cout << num << endl;
42     return 0;
43 }
View Code

 

posted @ 2017-07-30 15:07  wydxry  阅读(282)  评论(0编辑  收藏  举报
Live2D