Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Diff Checker
- Git stopped working because the diffing algorithm is buggy so guess who will have to re-implement it?
- 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.
- Study the examples below to get a clearer understanding.
- Input
- There are two lines of input, each one containing numbers, separated by a space.
- Output
- For each pair of elements, print a new line in the format:
- + {firstArrElement} {secondArrElement} - if equal
- - {firstArrElement} {secondArrElement} - if different
- Replace a missing element with 'x', if necessary.
- Sample Tests
- Input
- 1 2 3 4 5 7
- 1 2 4 4 5 6
- Output
- + 1 1
- + 2 2
- - 3 4
- + 4 4
- + 5 5
- - 7 6
- Input
- 1 2 3 4 5 6
- 1 2 3 4
- Output
- + 1 1
- + 2 2
- + 3 3
- + 4 4
- - 5 x
- - 6 x
- using System;
- namespace DGD_Vilio_2
- {
- class DiffChecker
- {
- static void Main(string[] args)
- {
- int[] arr1 = new int[100];
- int[] arr2 = new int[100];
- string input1 = Console.ReadLine();
- string input2 = Console.ReadLine();
- string split1;
- string split2;
- int arr_length;
- if (input1.Length > input2.Length)
- {
- arr_length = input1.Length / 2 + 1;
- }
- else {
- arr_length = input2.Length / 2 + 1;
- }
- for (int i = 0; i < arr_length; i++)
- {
- if (String.IsNullOrEmpty(input1.Split(" ")[i]) && !String.IsNullOrEmpty(input2.Split(" ")[i]))
- {
- split1 = "x";
- split2 = input2.Split(" ")[i];
- //Console.WriteLine("- x " + split2);
- }
- else if (String.IsNullOrEmpty(input2.Split(" ")[i]) && !String.IsNullOrEmpty(input1.Split(" ")[i]))
- {
- split1 = input1.Split(" ")[i];
- split2 = "x";
- //Console.WriteLine("- " + split1 + " x");
- }
- else {
- split1 = input1.Split(" ")[i];
- split2 = input2.Split(" ")[i];
- }
- if (split1.Equals(split2))
- {
- Console.WriteLine("+ " + split1 + " " + split2);
- }
- else if(!split1.Equals(split2)){
- Console.WriteLine("- " + split1 + " " + split2);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement