105 lines
3.1 KiB
C#
105 lines
3.1 KiB
C#
namespace strings_4;
|
|
|
|
class Program {
|
|
static void Main(string[] args) {
|
|
Menu();
|
|
}
|
|
|
|
static void Menu() {
|
|
Console.Clear();
|
|
int scelta;
|
|
string stringa1, stringa2;
|
|
do {
|
|
Console.WriteLine("Inserire un'opzione:");
|
|
Console.WriteLine("1. Conta spazi pre maiuscola");
|
|
Console.WriteLine("2. Converti in binario");
|
|
Console.WriteLine("3. Stampa a gruppi di 3");
|
|
Console.WriteLine("4. Codifica");
|
|
Console.WriteLine("5. Parola palindroma pari");
|
|
Console.WriteLine("0. Esci");
|
|
Console.Write("Scelta: ");
|
|
scelta = Convert.ToInt32(Console.ReadLine());
|
|
|
|
switch (scelta) {
|
|
case 0:
|
|
break;
|
|
case 1:
|
|
Console.Clear();
|
|
Console.WriteLine($"La stringa contiene {ContaSpaziPreMaiuscola(Input())} spazi prima di una maiuscola.");
|
|
Pausa();
|
|
break;
|
|
case 2:
|
|
Console.Clear();
|
|
Console.WriteLine(ToBinary());
|
|
Pausa();
|
|
break;
|
|
case 3:
|
|
Console.Clear();
|
|
GruppiDiTre(Input());
|
|
Pausa();
|
|
break;
|
|
case 4:
|
|
Console.Clear();
|
|
Pausa();
|
|
break;
|
|
case 5:
|
|
Console.Clear();
|
|
//Console.WriteLine(CreaPalindromo(Input(), true));
|
|
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 string Input() {
|
|
Console.Write("Inserire una frase: ");
|
|
return Console.ReadLine();
|
|
}
|
|
|
|
static int ContaSpaziPreMaiuscola(string p_stringa) {
|
|
int ritorno = 0, i = 0;
|
|
do {
|
|
if (p_stringa.IndexOf(' ') + i == -1) {
|
|
break;
|
|
}
|
|
|
|
if (char.IsUpper(p_stringa[p_stringa.IndexOf(' ') + i])) {
|
|
ritorno++;
|
|
p_stringa = p_stringa.Substring(p_stringa.IndexOf(' ') + i);
|
|
i = 0;
|
|
}
|
|
else {
|
|
i++;
|
|
}
|
|
}
|
|
while (p_stringa.Contains(' ') && p_stringa.IndexOf(' ') + i < p_stringa.Length);
|
|
return ritorno;
|
|
}
|
|
|
|
static string ToBinary() {
|
|
Console.Write("Inserire un numero: ");
|
|
return Convert.ToString(Convert.ToInt32(Console.ReadLine()), 2);
|
|
}
|
|
|
|
static void GruppiDiTre(string p_stringa) {
|
|
for (int i = 0; i < p_stringa.Length; i++) {
|
|
if (i % 3 == 0 && i != 0) {
|
|
Console.Write('-');
|
|
}
|
|
Console.Write(p_stringa[i]);
|
|
}
|
|
Console.WriteLine();
|
|
}
|
|
} |