Adeguamento traccia

This commit is contained in:
La Programmatrice Verde 2025-02-26 19:54:58 +01:00
parent 18037b27ff
commit a5905dea41

View File

@ -45,15 +45,7 @@ class Program {
break; break;
case 5: case 5:
Console.Clear(); Console.Clear();
stringa1 = Input(); Anagramma();
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");
}
Pausa(); Pausa();
break; break;
default: default:
@ -123,17 +115,14 @@ class Program {
Console.WriteLine(); Console.WriteLine();
} }
static char[] InsertionSort(char[] p_array) static char[] InsertionSort(char[] p_array) { //implementazione ufficiale copiata da Classroom
{ //implementazione ufficiale copiata da Classroom
int i, j; int i, j;
char temp; char temp;
for (i = 1; i < p_array.Length; i++) for (i = 1; i < p_array.Length; i++) {
{
temp = p_array[i]; temp = p_array[i];
j = i - 1; j = i - 1;
while (j >= 0 && p_array[j] > temp) while (j >= 0 && p_array[j] > temp) {
{
p_array[j + 1] = p_array[j]; p_array[j + 1] = p_array[j];
j--; j--;
} }
@ -142,4 +131,15 @@ class Program {
return p_array; 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");
}
}
} }