Opzione 3 furba

This commit is contained in:
La Programmatrice Verde 2025-02-17 22:01:35 +01:00
parent 9786e2adcd
commit 6415a06c85
9 changed files with 33 additions and 9 deletions

View File

@ -8,6 +8,7 @@ class Program {
static void Menu() { static void Menu() {
Console.Clear(); Console.Clear();
int scelta; int scelta;
const int LUNGHEZZA = 100;
string stringa1, stringa2; string stringa1, stringa2;
do { do {
Console.WriteLine("Inserire un'opzione:"); Console.WriteLine("Inserire un'opzione:");
@ -28,7 +29,7 @@ class Program {
Console.Clear(); Console.Clear();
stringa1 = Input(); stringa1 = Input();
stringa2 = Input(); stringa2 = Input();
if (Controllo(stringa1, stringa2)) { if (Controllo1(stringa1, stringa2)) {
Console.WriteLine(AlternaCaratteri(stringa1, stringa2)); Console.WriteLine(AlternaCaratteri(stringa1, stringa2));
} }
else { else {
@ -43,7 +44,14 @@ class Program {
break; break;
case 3: case 3:
Console.Clear(); Console.Clear();
Console.WriteLine(PrimoCarattereMaiuscolo(Input())); stringa1 = Input();
if (Controllo2(stringa1, LUNGHEZZA)) {
Console.WriteLine(PrimoCarattereMaiuscolo(stringa1));
}
else {
Console.WriteLine($"Errore: la frase non può essere più lunga di {LUNGHEZZA} caratteri");
}
Pausa(); Pausa();
break; break;
case 4: case 4:
@ -82,7 +90,7 @@ class Program {
return Console.ReadLine(); return Console.ReadLine();
} }
static bool Controllo(string p_stringa1, string p_stringa2) { static bool Controllo1(string p_stringa1, string p_stringa2) {
bool ritorno; bool ritorno;
if (p_stringa1.Length == p_stringa2.Length) { if (p_stringa1.Length == p_stringa2.Length) {
ritorno = true; ritorno = true;
@ -136,10 +144,26 @@ class Program {
return string.Join("", ritorno).Split(inutile).First(); return string.Join("", ritorno).Split(inutile).First();
} }
static string PrimoCarattereMaiuscolo(string p_stringa) { static bool Controllo2(string p_stringa1, int p_lunghezza) {
string ritorno = char.ToUpper(p_stringa[0]) + p_stringa.Split(p_stringa[0]).Last(); bool ritorno;
if (p_stringa1.Length < p_lunghezza) {
ritorno = true;
}
else {
ritorno = false;
}
return ritorno; return ritorno;
}
static string PrimoCarattereMaiuscolo(string p_stringa) {
string[] substrings = p_stringa.Split();
for (int i = 0; i < substrings.Length; i++) {
substrings[i] = char.ToUpper(substrings[i][0]) + substrings[i].Split(substrings[i][0]).Last().ToLower();
}
return string.Join(" ", substrings);
} }
} }

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+b2b1285d037b00410936752e5a623c5f2672c263")] [assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+9786e2adcd46bff810419c77a664ff038d4fb2bd")]
[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")]
// Generated by the MSBuild WriteCodeFragment class. // Generato dalla classe WriteCodeFragment di MSBuild.

View File

@ -1 +1 @@
ba2e54e8180aab2a82a9f8d460afffb6112678b22fc4465b8b01a6662a39f037 62074303f49b761550171178f383c453b8b19d1e02f472014128ddf26529322b

Binary file not shown.

Binary file not shown.