diff --git a/Program.cs b/Program.cs index 42a5260..795fd4a 100644 --- a/Program.cs +++ b/Program.cs @@ -1,9 +1,115 @@ namespace strings_2; -class Program -{ - static void Main(string[] args) - { - Console.WriteLine("Hello, World!"); +class Program { + static void Main(string[] args) { + Menu(); + } + + static void Menu() { + Console.Clear(); + int scelta; + do { + Console.WriteLine("Inserire un'opzione:"); + Console.WriteLine("1. Verifica parola palindroma"); + Console.WriteLine("2. Verifica frase palindroma"); + Console.WriteLine("3. Conta occorrenze"); + Console.WriteLine("4. Sostituisci lettera"); + Console.WriteLine("5. Prima lettere pari, poi dispari"); + Console.WriteLine("0. Esci"); + Console.Write("Scelta: "); + scelta = Convert.ToInt32(Console.ReadLine()); + + switch (scelta) { + case 0: + break; + case 1: + Console.Clear(); + if (Palindromo()) { + Console.WriteLine("La parola è palindroma"); + } + else{ + Console.WriteLine("La parola non è palindroma"); + } + Pausa(); + break; + case 2: + Console.Clear(); + + Pausa(); + break; + case 3: + Console.Clear(); + + Console.Clear(); + break; + case 4: + Console.Clear(); + + Pausa(); + break; + case 5: + Console.Clear(); + + Pausa(); + break; + default: + Console.WriteLine("Opzione non valida."); + Pausa(); + break; + } + } + while (scelta != 0); + } + + static void Pausa() { + Console.WriteLine("Premere un tasto per continuare. . ."); + Console.ReadKey(); + Console.Clear(); + } + + static char[] InsertionSort(char[] p_array) { //implementazione ufficiale copiata da Classroom + int i, j; + char temp; + + for (i = 1; i < p_array.Length; i++) { + temp = p_array[i]; + j = i - 1; + while (j >= 0 && p_array[j] > temp) { + p_array[j + 1] = p_array[j]; + j--; + } + p_array[j + 1] = temp; + } + + return p_array; + } + + static bool Palindromo() { + string stringa; + bool ritorno; + do { + Console.Write("Inserire una parola: "); + stringa = Console.ReadLine().ToLower(); //convertita in minuscolo per identificare palindromi case insensitive + if (stringa.Contains(' ')) { + Console.WriteLine("È consentito inserire solo una parola. Per inserire una frase scegliere l'opzione 2."); + Pausa(); + } + } + while (stringa.Contains(' ')); + + char[] metà1 = stringa.Substring(0, stringa.Length / 2).ToCharArray(); //divido la stringa a metà, prendo la prima e la converto in array di char per riordinarne le lettere + char[] metà2 = stringa.Substring(stringa.Length/2, stringa.Length/2).ToCharArray(); //divido la stringa a metà, prendo la seconda e la converto in array di char per riordinarne le lettere + + string metàOrdinata1 = string.Join("", InsertionSort(metà1));//ordino la prima metà della stringa e la riconverto da array di char in stringa + string metàOrdinata2 = string.Join("", InsertionSort(metà2));//ordino la secondo metà della stringa e la riconverto da array di char in stringa + //le due metà prima vengono convertite in array di char per riordinarle, poi vengono convertite in stringa dopo essere state ordinate per calcolarne l'hash con il metodo integrato + + if (metàOrdinata1.GetHashCode() == metàOrdinata2.GetHashCode()) {//se l'hash delle due metà ordinate coincide + ritorno = true; + } + else { + ritorno = false; + } + return ritorno; } } diff --git a/bin/Debug/net9.0/strings_2 b/bin/Debug/net9.0/strings_2 new file mode 100755 index 0000000..6654f9e Binary files /dev/null and b/bin/Debug/net9.0/strings_2 differ diff --git a/bin/Debug/net9.0/strings_2.deps.json b/bin/Debug/net9.0/strings_2.deps.json new file mode 100644 index 0000000..3cc4eea --- /dev/null +++ b/bin/Debug/net9.0/strings_2.deps.json @@ -0,0 +1,23 @@ +{ + "runtimeTarget": { + "name": ".NETCoreApp,Version=v9.0", + "signature": "" + }, + "compilationOptions": {}, + "targets": { + ".NETCoreApp,Version=v9.0": { + "strings_2/1.0.0": { + "runtime": { + "strings_2.dll": {} + } + } + } + }, + "libraries": { + "strings_2/1.0.0": { + "type": "project", + "serviceable": false, + "sha512": "" + } + } +} \ No newline at end of file diff --git a/bin/Debug/net9.0/strings_2.dll b/bin/Debug/net9.0/strings_2.dll new file mode 100644 index 0000000..f61d5b5 Binary files /dev/null and b/bin/Debug/net9.0/strings_2.dll differ diff --git a/bin/Debug/net9.0/strings_2.pdb b/bin/Debug/net9.0/strings_2.pdb new file mode 100644 index 0000000..36f1fd6 Binary files /dev/null and b/bin/Debug/net9.0/strings_2.pdb differ diff --git a/bin/Debug/net9.0/strings_2.runtimeconfig.json b/bin/Debug/net9.0/strings_2.runtimeconfig.json new file mode 100644 index 0000000..b19c3c8 --- /dev/null +++ b/bin/Debug/net9.0/strings_2.runtimeconfig.json @@ -0,0 +1,12 @@ +{ + "runtimeOptions": { + "tfm": "net9.0", + "framework": { + "name": "Microsoft.NETCore.App", + "version": "9.0.0" + }, + "configProperties": { + "System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false + } + } +} \ No newline at end of file diff --git a/obj/Debug/net9.0/.NETCoreApp,Version=v9.0.AssemblyAttributes.cs b/obj/Debug/net9.0/.NETCoreApp,Version=v9.0.AssemblyAttributes.cs new file mode 100644 index 0000000..9e76325 --- /dev/null +++ b/obj/Debug/net9.0/.NETCoreApp,Version=v9.0.AssemblyAttributes.cs @@ -0,0 +1,4 @@ +// +using System; +using System.Reflection; +[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v9.0", FrameworkDisplayName = ".NET 9.0")] diff --git a/obj/Debug/net9.0/apphost b/obj/Debug/net9.0/apphost new file mode 100755 index 0000000..6654f9e Binary files /dev/null and b/obj/Debug/net9.0/apphost differ diff --git a/obj/Debug/net9.0/ref/strings_2.dll b/obj/Debug/net9.0/ref/strings_2.dll new file mode 100644 index 0000000..dee7003 Binary files /dev/null and b/obj/Debug/net9.0/ref/strings_2.dll differ diff --git a/obj/Debug/net9.0/refint/strings_2.dll b/obj/Debug/net9.0/refint/strings_2.dll new file mode 100644 index 0000000..dee7003 Binary files /dev/null and b/obj/Debug/net9.0/refint/strings_2.dll differ diff --git a/obj/Debug/net9.0/strings_2.AssemblyInfo.cs b/obj/Debug/net9.0/strings_2.AssemblyInfo.cs new file mode 100644 index 0000000..28379c8 --- /dev/null +++ b/obj/Debug/net9.0/strings_2.AssemblyInfo.cs @@ -0,0 +1,22 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +using System; +using System.Reflection; + +[assembly: System.Reflection.AssemblyCompanyAttribute("strings_2")] +[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] +[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+df4f2918a49cbd8aeeebe19777d71532803e253e")] +[assembly: System.Reflection.AssemblyProductAttribute("strings_2")] +[assembly: System.Reflection.AssemblyTitleAttribute("strings_2")] +[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] + +// Generated by the MSBuild WriteCodeFragment class. + diff --git a/obj/Debug/net9.0/strings_2.AssemblyInfoInputs.cache b/obj/Debug/net9.0/strings_2.AssemblyInfoInputs.cache new file mode 100644 index 0000000..fbd1cd7 --- /dev/null +++ b/obj/Debug/net9.0/strings_2.AssemblyInfoInputs.cache @@ -0,0 +1 @@ +69f869a208dc09bd1be386fdbbafe9f6913df04b08dc4f24906dd6e708dc41ef diff --git a/obj/Debug/net9.0/strings_2.GeneratedMSBuildEditorConfig.editorconfig b/obj/Debug/net9.0/strings_2.GeneratedMSBuildEditorConfig.editorconfig new file mode 100644 index 0000000..7926b43 --- /dev/null +++ b/obj/Debug/net9.0/strings_2.GeneratedMSBuildEditorConfig.editorconfig @@ -0,0 +1,15 @@ +is_global = true +build_property.TargetFramework = net9.0 +build_property.TargetPlatformMinVersion = +build_property.UsingMicrosoftNETSdkWeb = +build_property.ProjectTypeGuids = +build_property.InvariantGlobalization = +build_property.PlatformNeutralAssembly = +build_property.EnforceExtendedAnalyzerRules = +build_property._SupportedPlatformList = Linux,macOS,Windows +build_property.RootNamespace = strings_2 +build_property.ProjectDir = /home/Verde/git/strings_2/ +build_property.EnableComHosting = +build_property.EnableGeneratedComInterfaceComImportInterop = +build_property.EffectiveAnalysisLevelStyle = 9.0 +build_property.EnableCodeStyleSeverity = diff --git a/obj/Debug/net9.0/strings_2.GlobalUsings.g.cs b/obj/Debug/net9.0/strings_2.GlobalUsings.g.cs new file mode 100644 index 0000000..8578f3d --- /dev/null +++ b/obj/Debug/net9.0/strings_2.GlobalUsings.g.cs @@ -0,0 +1,8 @@ +// +global using global::System; +global using global::System.Collections.Generic; +global using global::System.IO; +global using global::System.Linq; +global using global::System.Net.Http; +global using global::System.Threading; +global using global::System.Threading.Tasks; diff --git a/obj/Debug/net9.0/strings_2.assets.cache b/obj/Debug/net9.0/strings_2.assets.cache new file mode 100644 index 0000000..320de29 Binary files /dev/null and b/obj/Debug/net9.0/strings_2.assets.cache differ diff --git a/obj/Debug/net9.0/strings_2.csproj.CoreCompileInputs.cache b/obj/Debug/net9.0/strings_2.csproj.CoreCompileInputs.cache new file mode 100644 index 0000000..22d4e6b --- /dev/null +++ b/obj/Debug/net9.0/strings_2.csproj.CoreCompileInputs.cache @@ -0,0 +1 @@ +4ef1c6e281a4279efbe6a93ea283d646bf9f249445f7fe51ef3162564a07b622 diff --git a/obj/Debug/net9.0/strings_2.csproj.FileListAbsolute.txt b/obj/Debug/net9.0/strings_2.csproj.FileListAbsolute.txt new file mode 100644 index 0000000..cbb43c1 --- /dev/null +++ b/obj/Debug/net9.0/strings_2.csproj.FileListAbsolute.txt @@ -0,0 +1,14 @@ +/home/Verde/git/strings_2/bin/Debug/net9.0/strings_2 +/home/Verde/git/strings_2/bin/Debug/net9.0/strings_2.deps.json +/home/Verde/git/strings_2/bin/Debug/net9.0/strings_2.runtimeconfig.json +/home/Verde/git/strings_2/bin/Debug/net9.0/strings_2.dll +/home/Verde/git/strings_2/bin/Debug/net9.0/strings_2.pdb +/home/Verde/git/strings_2/obj/Debug/net9.0/strings_2.GeneratedMSBuildEditorConfig.editorconfig +/home/Verde/git/strings_2/obj/Debug/net9.0/strings_2.AssemblyInfoInputs.cache +/home/Verde/git/strings_2/obj/Debug/net9.0/strings_2.AssemblyInfo.cs +/home/Verde/git/strings_2/obj/Debug/net9.0/strings_2.csproj.CoreCompileInputs.cache +/home/Verde/git/strings_2/obj/Debug/net9.0/strings_2.dll +/home/Verde/git/strings_2/obj/Debug/net9.0/refint/strings_2.dll +/home/Verde/git/strings_2/obj/Debug/net9.0/strings_2.pdb +/home/Verde/git/strings_2/obj/Debug/net9.0/strings_2.genruntimeconfig.cache +/home/Verde/git/strings_2/obj/Debug/net9.0/ref/strings_2.dll diff --git a/obj/Debug/net9.0/strings_2.dll b/obj/Debug/net9.0/strings_2.dll new file mode 100644 index 0000000..f61d5b5 Binary files /dev/null and b/obj/Debug/net9.0/strings_2.dll differ diff --git a/obj/Debug/net9.0/strings_2.genruntimeconfig.cache b/obj/Debug/net9.0/strings_2.genruntimeconfig.cache new file mode 100644 index 0000000..7dde8ec --- /dev/null +++ b/obj/Debug/net9.0/strings_2.genruntimeconfig.cache @@ -0,0 +1 @@ +8e63a3e5c8184e4803384ce467b66ca113025ee9ae0a3ebb80cacd36228a9b4f diff --git a/obj/Debug/net9.0/strings_2.pdb b/obj/Debug/net9.0/strings_2.pdb new file mode 100644 index 0000000..36f1fd6 Binary files /dev/null and b/obj/Debug/net9.0/strings_2.pdb differ