Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Solution {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- String len = sc.nextLine();
- String str = sc.nextLine();
- int blocks = 1;
- char temp;
- char prev = str.charAt(0);
- for(int i = 1; i < str.length(); i ++){
- temp = str.charAt(i);
- if(temp == prev){
- blocks++;
- }
- else{
- if(temp == '1'){
- while(blocks != 1){
- System.out.print(0);
- blocks--;
- }
- }
- else{
- System.out.print(blocks);
- }
- blocks = 1;
- }
- prev = temp;
- if(i == str.length() - 1 && temp == '1'){
- System.out.print(blocks);
- }
- if(i == str.length() - 1 && temp == '0'){
- while(blocks != 1){
- System.out.print(0);
- blocks--;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement