Advertisement
ibragimova_mariam

Untitled

Jul 17th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Solution {
  4.  
  5. public static void main(String[] args) {
  6.  
  7.  
  8. Scanner sc = new Scanner(System.in);
  9. String len = sc.nextLine();
  10. String str = sc.nextLine();
  11.  
  12. int blocks = 1;
  13. char temp;
  14. char prev = str.charAt(0);
  15.  
  16. for(int i = 1; i < str.length(); i ++){
  17. temp = str.charAt(i);
  18. if(temp == prev){
  19. blocks++;
  20. }
  21. else{
  22. if(temp == '1'){
  23. while(blocks != 1){
  24. System.out.print(0);
  25. blocks--;
  26. }
  27. }
  28. else{
  29. System.out.print(blocks);
  30. }
  31. blocks = 1;
  32. }
  33. prev = temp;
  34. if(i == str.length() - 1 && temp == '1'){
  35. System.out.print(blocks);
  36. }
  37. if(i == str.length() - 1 && temp == '0'){
  38. while(blocks != 1){
  39. System.out.print(0);
  40. blocks--;
  41. }
  42. }
  43. }
  44.  
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement