Modifica opzione 1 per rendere più contenta la prof

This commit is contained in:
La Programmatrice Verde 2025-02-17 09:02:27 +01:00
parent 8d0599b65c
commit b2b1285d03
9 changed files with 32 additions and 30 deletions

View File

@ -8,7 +8,7 @@ class Program {
static void Menu() { static void Menu() {
Console.Clear(); Console.Clear();
int scelta; int scelta;
string stringa; string stringa1, stringa2;
do { do {
Console.WriteLine("Inserire un'opzione:"); Console.WriteLine("Inserire un'opzione:");
Console.WriteLine("1. Alterna i caratteri"); Console.WriteLine("1. Alterna i caratteri");
@ -26,7 +26,14 @@ class Program {
break; break;
case 1: case 1:
Console.Clear(); Console.Clear();
AlternaCaratteri(); stringa1 = Input();
stringa2 = Input();
if (Controllo(stringa1, stringa2)) {
Console.WriteLine(AlternaCaratteri(stringa1, stringa2));
}
else {
Console.WriteLine("Errore: le due stringhe devono essere lunghe uguali");
}
Pausa(); Pausa();
break; break;
case 2: case 2:
@ -75,32 +82,27 @@ class Program {
return Console.ReadLine(); return Console.ReadLine();
} }
static void AlternaCaratteri() { static bool Controllo(string p_stringa1, string p_stringa2) {
string stringa1 = Input(); bool ritorno;
string stringa2 = Input(); if (p_stringa1.Length == p_stringa2.Length) {
bool stringa1Max = stringa1.Length > stringa2.Length; ritorno = true;
int lunghezza = stringa1Max ? stringa1.Length : stringa2.Length;
for (int i = 0; i < lunghezza; i++) {
if (stringa1Max) {
if (i < stringa2.Length) {
Console.Write($"{stringa1[i]}{stringa2[i]}");
} }
else { else {
Console.Write(stringa1[i]); ritorno = false;
}
}
else {
if (i < stringa1.Length) {
Console.Write($"{stringa1[i]}{stringa2[i]}");
}
else {
Console.Write(stringa2[i]);
}
} }
return ritorno;
} }
Console.WriteLine();
static string AlternaCaratteri(string p_stringa1, string p_stringa2) {
string ritorno = "";
for (int i = 0; i < p_stringa1.Length; i++) {
ritorno = string.Concat(ritorno, p_stringa1[i], p_stringa2[i]);
}
return ritorno;
} }
static string Codifica() { static string Codifica() {

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -13,10 +13,10 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("strings_3")] [assembly: System.Reflection.AssemblyCompanyAttribute("strings_3")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+d29d204ee494646ce5094700197a900b05cc44aa")] [assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+8d0599b65c9adc395c7a863ae0c292a2ea4126c5")]
[assembly: System.Reflection.AssemblyProductAttribute("strings_3")] [assembly: System.Reflection.AssemblyProductAttribute("strings_3")]
[assembly: System.Reflection.AssemblyTitleAttribute("strings_3")] [assembly: System.Reflection.AssemblyTitleAttribute("strings_3")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
// Generato dalla classe WriteCodeFragment di MSBuild. // Generated by the MSBuild WriteCodeFragment class.

View File

@ -1 +1 @@
cbb955859c30d97643b375ba8ca1883b485f554c16cef8a828a4aa0bf8968236 2a1edca03dfab0d51deb008cf18acd10fc7a6338349d06d54d7fc8dfb3ff671e

Binary file not shown.

Binary file not shown.