A.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 /*题目大意:有一种特殊的二进制,1代表一个贡献, 2 如3代表111,5代表11111,每个数字之间用0隔开, 3 如506就是111110111111,有一种特殊的情况就是100, 4 就代表两个0分割开的数字是0,没有贡献 5 6 题目思路:我们碰到1,贡献加1,碰到0, 7 输出这个贡献,贡献清零,需要注意的是最后还要继续输出这个贡献, 8 因为最后一位数后面没有零 9 */ 10 #include <iostream> 11 #include <stdio.h> 12 using namespace std; 13 int main(){ 14 int n,a[95],m=0,b; 15 for(int i=0;i<n;i++) 16 cin>>a[i]; 17 for(int i=0;i<n;i++) { 18 if(a[i]!=0) m++; 19 else if(a[i+1]==0) b=0; 20 else if(a[i+1]!=0) m++; 21 } 22 printf("%d",m); 23 }
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步