A - Binary Protocol
Solution :
- [tab]
- C++
#include<bits/stdc++.h> using namespace std; int main() { int i,j=1,n; string s; cin>>n>>s; for(i=1;i<n;i++) { if(s[i]=='0') { cout<<j; j=0; } else { j++; } } cout<<j<<"\n"; return 0; }
- Python 3
input() s = input().split('0') for i in s: print(len(i), end='')
- JAVA
import java.util.*; public class Z825A { public static void decode(String line) { int sum = 0; for(int i=0;i<line.length();++i) { if(line.charAt(i) == '0') { System.out.print(sum); sum = 0; } else { ++sum; } } System.out.print(sum); } public static void main(String[] args) { Scanner input = new Scanner(System.in); int n = input.nextInt(); String line = input.next(); decode(line); } }