My solution

master
Baltazár Radics 2020-09-25 21:45:47 +02:00
parent d1e40ee119
commit 7ac0a5884e
Signed by: baltazar
GPG Key ID: 9440F591E4397C3E
1 changed files with 43 additions and 1 deletions

View File

@ -1,18 +1,60 @@
using System;
class Program {
static void Main(string[] args) {
static int Main(string[] args) {
// 1.
{
Console.Write("E1: Enter string [+-0]: ");
string str = Console.ReadLine();
int x = 1;
foreach (char c in str) switch (c) {
case '+': ++x; break;
case '-': --x; break;
case '0': x = 0; break;
default:
Console.WriteLine("Invalid character: '"+c+"'!");
return 1;
}
Console.WriteLine(x);
}
// 2.
{
Console.Write("E2: Enter string [+-0!]: ");
string str = Console.ReadLine();
int x = 1;
foreach (char c in str) switch (c) {
case '+': ++x; break;
case '-': --x; break;
case '0': x = 0; break;
case '!':
if (x == 0) break;
int s = x < 0 ? 1 : -1;
for (int i = x+s; i != 0; i += s) x *= i;
break;
default:
Console.WriteLine("Invalid character: '"+c+"'!");
return 1;
}
Console.WriteLine(x);
}
// 3.
{
Console.Write("E3: Enter a word: ");
string str = Console.ReadLine();
for (int i = 0; i < str.Length; i += 2)
Console.Write(str[i]);
Console.WriteLine();
}
// 4.
{
Console.Write("E4: Enter words: ");
string str = Console.ReadLine();
string[] split = str.Split(' ');
for (int i = 0; i < split.Length; i += 2)
Console.Write(split[i] + ' ');
Console.WriteLine();
}
return 0;
}
}