Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* You are given n numbers. Write a program to find among these numbers all sets of 4 numbers {a, b, c, d}, such that a|b == c|d, where a ≠ b ≠ c ≠ d. Assume that "a|b" means to append the number b after a. We call these numbers {a, b, c, d} stuck numbers: if we append a and b, we get the same result as if we appended c and d. Note that the numbers a, b, c and d should be distinct (a ≠ b ≠ c ≠ d).
- * Print at the console all stuck numbers {a, b, c, d} found in the input sequence in format "a|b==c|d" (without any spaces), each at a separate line. The order of the output lines is not important. Print "No" in case no stuck numbers exist among the input sequence of numbers. */
- namespace _09.StuckNumbers
- {
- using System;
- class StuckNumbers
- {
- private static bool _isFoundStuckNum = false;
- static void Main(string[] args)
- {
- int count = int.Parse(Console.ReadLine());
- string[] numbers = Console.ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
- foreach (string a in numbers)
- {
- foreach (string b in numbers)
- {
- if (b != a)
- {
- foreach (string c in numbers)
- {
- if (c != a && c != b)
- {
- foreach (string d in numbers)
- {
- if (d != a && d != b && d != c)
- {
- CheckForStuckNumber(a, b, c, d);
- }
- }
- }
- }
- }
- }
- }
- if (!_isFoundStuckNum)
- {
- Console.WriteLine("No");
- }
- }
- private static void CheckForStuckNumber(string numA, string numB, string numC, string numD)
- {
- if ((numA + numB).Equals((numC + numD)))
- {
- _isFoundStuckNum = true;
- Console.WriteLine("{0}|{1}=={2}|{3}", numA, numB, numC, numD);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement