Advertisement
kalin729

dgd

Nov 26th, 2020
900
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.65 KB | None | 0 0
  1. Diff Checker
  2. Git stopped working because the diffing algorithm is buggy so guess who will have to re-implement it?
  3.  
  4. To start with something simpler, you will need to compare two arrays, and display a + if there's a match between a pair of elements or a - if there is none. If there are more numbers in one of the arrays, display a 'x' for the missing number in the other array.
  5.  
  6. Study the examples below to get a clearer understanding.
  7.  
  8. Input
  9. There are two lines of input, each one containing numbers, separated by a space.
  10. Output
  11. For each pair of elements, print a new line in the format:
  12. + {firstArrElement} {secondArrElement} - if equal
  13. - {firstArrElement} {secondArrElement} - if different
  14. Replace a missing element with 'x', if necessary.
  15. Sample Tests
  16. Input
  17. 1 2 3 4 5 7
  18. 1 2 4 4 5 6
  19. Output
  20. + 1 1
  21. + 2 2
  22. - 3 4
  23. + 4 4
  24. + 5 5
  25. - 7 6
  26. Input
  27. 1 2 3 4 5 6
  28. 1 2 3 4
  29. Output
  30. + 1 1
  31. + 2 2
  32. + 3 3
  33. + 4 4
  34. - 5 x
  35. - 6 x
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48. using System;
  49.  
  50. namespace DGD_Vilio_2
  51. {
  52.    class DiffChecker
  53.    {
  54.        static void Main(string[] args)
  55.        {
  56.            int[] arr1 = new int[100];
  57.            int[] arr2 = new int[100];
  58.  
  59.            string input1 = Console.ReadLine();
  60.            string input2 = Console.ReadLine();
  61.  
  62.            string split1;
  63.            string split2;
  64.  
  65.            int arr_length;
  66.            if (input1.Length > input2.Length)
  67.            {
  68.                arr_length = input1.Length / 2 + 1;
  69.            }
  70.            else {
  71.                arr_length = input2.Length / 2 + 1;
  72.            }
  73.  
  74.            for (int i = 0; i < arr_length; i++)
  75.            {
  76.                if (String.IsNullOrEmpty(input1.Split(" ")[i]) && !String.IsNullOrEmpty(input2.Split(" ")[i]))
  77.                {
  78.                    split1 = "x";
  79.                    split2 = input2.Split(" ")[i];
  80.                    //Console.WriteLine("- x " + split2);
  81.                }
  82.                else if (String.IsNullOrEmpty(input2.Split(" ")[i]) && !String.IsNullOrEmpty(input1.Split(" ")[i]))
  83.                {
  84.                    split1 = input1.Split(" ")[i];
  85.                    split2 = "x";
  86.                    //Console.WriteLine("- " + split1 + " x");
  87.                }
  88.                else {
  89.                    split1 = input1.Split(" ")[i];
  90.                    split2 = input2.Split(" ")[i];
  91.                }
  92.  
  93.                if (split1.Equals(split2))
  94.                {
  95.                    Console.WriteLine("+ " + split1 + " " + split2);
  96.                }
  97.                else if(!split1.Equals(split2)){
  98.                    Console.WriteLine("- " + split1 + " " + split2);
  99.                }
  100.  
  101.            }
  102.        }
  103.    }
  104. }
  105.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement