ivan_gy6ev

Compare Char Arrays

Jun 14th, 2017
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.57 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _05.Compare_Char_Arrays
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             var arr1 = Console.ReadLine()
  14.                 .Split( ).Select(char.Parse).ToArray();
  15.             var arr2 = Console.ReadLine()
  16.                 .Split( ).Select(char.Parse).ToArray();
  17.  
  18.             var minLength = Math.Min(arr1.Length, arr2.Length);
  19.             OrderArraysFromBiggerToLower(arr1,arr2);            
  20.         }
  21.         private static void OrderArraysFromBiggerToLower(char[] arr1Chars, char[] arr2Chars)
  22.         {
  23.             string result = string.Empty;
  24.             for (int i = 0; i < arr1Chars.Length - 1; i++)
  25.             {
  26.                 for (int j = 0; j < arr2Chars.Length - 1; j++)
  27.                 {
  28.                     //Console.WriteLine("{0}<->{1}",
  29.                     //    arr1Chars[i], arr2Chars[j]);
  30.                     if (arr1Chars[i] == arr2Chars[j])
  31.                     {
  32.                         result = "equal";
  33.                         //Console.WriteLine("{0} -<", result);
  34.                         if (arr1Chars.Length<arr2Chars.Length)
  35.                         {
  36.                             Console.WriteLine(string.Join("", arr1Chars));
  37.                             Console.WriteLine(string.Join("", arr2Chars));
  38.                         }
  39.                         else if(arr1Chars.Length>arr2Chars.Length)
  40.                         {
  41.                             Console.WriteLine(string.Join("", arr2Chars));
  42.                             Console.WriteLine(string.Join("", arr1Chars));
  43.                         }
  44.                     }
  45.                     else if (arr1Chars[i]<arr2Chars[j])
  46.                     {
  47.                         result = "arr1";
  48.                         //Console.WriteLine("{0} -<", result);
  49.                         Console.WriteLine(string.Join("", arr1Chars));
  50.                         Console.WriteLine(string.Join("", arr2Chars));
  51.                     }
  52.                     else if (arr1Chars[i]>arr2Chars[j])
  53.                     {
  54.                         result = "arr2";
  55.                         //Console.WriteLine("{0} -<", result);
  56.                         Console.WriteLine(string.Join("", arr2Chars));
  57.                         Console.WriteLine(string.Join("", arr1Chars));
  58.                     }
  59.                     if (result != string.Empty) break;
  60.                 }
  61.                 if (result != string.Empty) break;
  62.             }            
  63.         }
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment