Commit 641320fc authored by Uwe Wienkop's avatar Uwe Wienkop

18.11.19 Mo

parent 1e480435
......@@ -26,6 +26,9 @@ namespace _06StringsIntro1
Console.WriteLine((char) 7);
string[] Tiere = { "Elefant", "Otter", "Schlange" };
s = "";
s = "Elefant" + "enhaus";
// s[3] = 'F'; // Strings sind readonly!!!
s = "Elefant"; // Strings in DOPPELTEN Anführungszeichen
char[] erg = new char[s.Length];
erg[0] = s[0];
......
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<RootNamespace>_07Palindrom</RootNamespace>
</PropertyGroup>
</Project>
using System;
namespace _07Palindrom
{
class Program
{
// Stufe 1: Palindrome mit exaktem Zeichenvergleich; Bsp. ANNA
// Stufe 2: Toleranz gegenüber Groß-/Kleinschreibung; Bsp Anna
// Stufe 3: Leer- & Sonderzeichen/Satzzeichen werden überlesen
// Bsp.: Regal mit Sirup pur ist im Lager!
static bool IstPalindrom(string s)
{
//int i = 0, j = s.Length - 1;
//while (i<j)
//{
// i++;
// j--;
//}
for (int i = 0, j = s.Length - 1; i < j; i++, j--)
{
}
return true;
}
static void Main(string[] args)
{
string s = "ANNA"; // "BURGGRUB";
Console.WriteLine($"{s} ist Palindrom: {IstPalindrom(s)}");
}
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<RootNamespace>_07String2Int</RootNamespace>
</PropertyGroup>
</Project>
using System;
namespace _07String2Int
{
class Program
{
static int Convert2Int(string s, int basis = 10)
{
int zahl = 0;
foreach (char ziffer in s)
{
zahl = zahl * basis + (ziffer - '0');
}
return zahl;
}
static string Convert2String(int zahl, int basis = 10)
{
string erg = "";
do
{
erg = (char)(zahl % basis + '0') + erg;
zahl /= basis;
} while (zahl > 0);
return erg;
}
static string CaesarCodierung(string s, int offset = 1)
{
string erg = "";
foreach (char z in s)
{
//char neu = (char)(z + offset);
//if (neu > 'Z')
// neu = (char) (neu- 26);
char neu = (char)((z - 'A' + offset + 26) % 26 + 'A');
erg += neu;
}
return erg;
}
/// <summary>
///
/// </summary>
/// <param name="s1"></param>
/// <param name="s2"></param>
/// <returns>negativer Wert: s1<s2
/// positiver Wert: s2>s1
/// == 0 s1==s2</returns>
static int CompareTo(string s1, string s2)
{
int ende = Math.Min(s1.Length, s2.Length);
for (int i = 0; i < ende; i++)
{
int dif = s1[i] - s2[i];
if (dif != 0)
return dif;
}
return s1.Length - s2.Length;
}
static void Main(string[] args)
{
Console.WriteLine(Convert2Int("1100") * 2);
Console.WriteLine(Convert2String(257, 2));
Console.WriteLine(CaesarCodierung("ABCXYZ", 1));
Console.WriteLine(CaesarCodierung("ABCXYZ", -1));
Console.WriteLine();
string s = "DIEKLAUSURISTAMACHZEHNTENJANUAR";
Random wuerfel = new Random();
string verschluesselt = CaesarCodierung(s, wuerfel.Next(1, 26));
for (int i = -1; i >= -25; i--)
{
Console.WriteLine(CaesarCodierung(verschluesselt, i));
}
bool[] weitererVersuch = new bool[26];
while (true)
{
int c = Console.ReadKey().KeyChar ;
if (c >= 'a' && c <= 'z')
{ // 'a' .. 'z' = 97 .. 122.
c -= 'a'; // => 0 .. 25
if (weitererVersuch[c])
Console.WriteLine($"Das Zeichen '{(char)(c+'a')}' wurde bereits verwendet");
else
{
Console.WriteLine($"Erster Versuch dem dem Zeichen '{(char)(c+'a')}'");
weitererVersuch[c] = true;
}
}
}
}
}
}
......@@ -51,9 +51,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "06FelderSortieren", "06Feld
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "06FelderHistogramme", "06FelderHistogramme\06FelderHistogramme.csproj", "{0287FEC1-5015-4789-A33D-5A1B66B30E77}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "06Felder2D", "06Felder2D\06Felder2D.csproj", "{C8207FFC-FFF8-411F-9C13-931E27B11179}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "06Felder2D", "06Felder2D\06Felder2D.csproj", "{C8207FFC-FFF8-411F-9C13-931E27B11179}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "06StringsIntro1", "06StringsIntro1\06StringsIntro1.csproj", "{F01CE4B4-E2C5-4749-9166-8521B5230222}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "06StringsIntro1", "06StringsIntro1\06StringsIntro1.csproj", "{F01CE4B4-E2C5-4749-9166-8521B5230222}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "07String2Int", "07String2Int\07String2Int.csproj", "{2C5684D9-4566-4F7D-AA5D-4F9C1843C38A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "07Palindrom", "07Palindrom\07Palindrom.csproj", "{7C1C70D7-6C1C-4DE3-AD09-C6ECE19B3DAE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
......@@ -165,6 +169,14 @@ Global
{F01CE4B4-E2C5-4749-9166-8521B5230222}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F01CE4B4-E2C5-4749-9166-8521B5230222}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F01CE4B4-E2C5-4749-9166-8521B5230222}.Release|Any CPU.Build.0 = Release|Any CPU
{2C5684D9-4566-4F7D-AA5D-4F9C1843C38A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2C5684D9-4566-4F7D-AA5D-4F9C1843C38A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2C5684D9-4566-4F7D-AA5D-4F9C1843C38A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2C5684D9-4566-4F7D-AA5D-4F9C1843C38A}.Release|Any CPU.Build.0 = Release|Any CPU
{7C1C70D7-6C1C-4DE3-AD09-C6ECE19B3DAE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7C1C70D7-6C1C-4DE3-AD09-C6ECE19B3DAE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7C1C70D7-6C1C-4DE3-AD09-C6ECE19B3DAE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7C1C70D7-6C1C-4DE3-AD09-C6ECE19B3DAE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment