diff --git a/Program.cs b/Program.cs index 880041f..6f026c4 100644 --- a/Program.cs +++ b/Program.cs @@ -45,15 +45,7 @@ class Program { break; case 5: Console.Clear(); - stringa1 = Input(); - stringa2 = Input(); - if (string.Join("", InsertionSort(stringa1.ToLower().ToCharArray())).GetHashCode() - == string.Join("", InsertionSort(stringa2.ToLower().ToCharArray())).GetHashCode()) { - Console.WriteLine("Le due stringhe sono anagrammi"); - } - else { - Console.WriteLine("Le due stringhe non sono anagrammi"); - } + Anagramma(); Pausa(); break; default: @@ -123,17 +115,14 @@ class Program { Console.WriteLine(); } - static char[] InsertionSort(char[] p_array) - { //implementazione ufficiale copiata da Classroom + static char[] InsertionSort(char[] p_array) { //implementazione ufficiale copiata da Classroom int i, j; char temp; - for (i = 1; i < p_array.Length; i++) - { + for (i = 1; i < p_array.Length; i++) { temp = p_array[i]; j = i - 1; - while (j >= 0 && p_array[j] > temp) - { + while (j >= 0 && p_array[j] > temp) { p_array[j + 1] = p_array[j]; j--; } @@ -142,4 +131,15 @@ class Program { return p_array; } + + static void Anagramma() { + //stessa logica dei punti 1 e 2 dell'esercizio strings_2, solo che รจ un one-liner + if (string.Join("", InsertionSort(Input().ToLower().ToCharArray())).GetHashCode() + == string.Join("", InsertionSort(Input().ToLower().ToCharArray())).GetHashCode()) { + Console.WriteLine("Le due stringhe sono anagrammi"); + } + else { + Console.WriteLine("Le due stringhe non sono anagrammi"); + } + } } \ No newline at end of file