Advertisement
Guest User

Untitled

a guest
Nov 26th, 2018
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.21 KB | None | 0 0
  1. public class Hello{
  2.     public static int[] Sol(int[] a){
  3.         // Your code here!
  4.         int[] b = new int[a.Length];
  5.         for(int i = a.Length - 1; i > 0; i--){
  6.             b[i] += a[i];
  7.             b[i - 1] += a[i];
  8.         }
  9.         foreach(int e in b) System.Console.Write(e);
  10.         System.Console.WriteLine();
  11.         for(int i = 0; i < a.Length - 1; i++){
  12.             while(b[i] > 1){
  13.                 b[i] -= 2;
  14.                 b[i+1]--;
  15.             }
  16.         }
  17.         if(a[0] == 1){
  18.             if(b[0] == 0) b[0]++;
  19.             else{
  20.                 b[0]--;
  21.                 b[1]--;
  22.                 for(int i = 0; i < a.Length; i++){
  23.                     while(b[i] < 0){
  24.                         b[i] += 2;
  25.                         b[i + 1]--;
  26.                     }
  27.                 }
  28.             }
  29.         }
  30.         while(b[b.Length - 1] == 0){
  31.             System.Array.Resize(ref b, b.Length - 1);
  32.         }
  33.         foreach(int e in b) System.Console.Write(e);
  34.         System.Console.WriteLine();
  35.         return b;
  36.     }
  37.    
  38.     public static void Main(){
  39.         int[] a = new int[] {1, 0, 0, 1, 1};
  40.         Sol(a);
  41.         a = new int[] {1, 0, 0, 1, 1, 1};
  42.         Sol(a);
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement