Adeguamento traccia
This commit is contained in:
parent
18037b27ff
commit
a5905dea41
30
Program.cs
30
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user