Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Hello{
- public static int[] Sol(int[] a){
- // Your code here!
- int[] b = new int[a.Length];
- for(int i = a.Length - 1; i > 0; i--){
- b[i] += a[i];
- b[i - 1] += a[i];
- }
- foreach(int e in b) System.Console.Write(e);
- System.Console.WriteLine();
- for(int i = 0; i < a.Length - 1; i++){
- while(b[i] > 1){
- b[i] -= 2;
- b[i+1]--;
- }
- }
- if(a[0] == 1){
- if(b[0] == 0) b[0]++;
- else{
- b[0]--;
- b[1]--;
- for(int i = 0; i < a.Length; i++){
- while(b[i] < 0){
- b[i] += 2;
- b[i + 1]--;
- }
- }
- }
- }
- while(b[b.Length - 1] == 0){
- System.Array.Resize(ref b, b.Length - 1);
- }
- foreach(int e in b) System.Console.Write(e);
- System.Console.WriteLine();
- return b;
- }
- public static void Main(){
- int[] a = new int[] {1, 0, 0, 1, 1};
- Sol(a);
- a = new int[] {1, 0, 0, 1, 1, 1};
- Sol(a);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement