Andra problemet dag 5 , löst

This commit is contained in:
2018-12-16 08:44:36 +01:00
parent e060afed52
commit 2d6af925f4

View File

@ -35,6 +35,48 @@ namespace _2018_05
ReadKey();
string nextStr = StringReduce(ref removes, resTab);
int winner = nextStr.Length;
string wrkWin = "";
foreach (char y in charset)
{
string wrk = "";
wrk += y;
if (wrk != wrk.ToLower())
{
string tmpResTab = "";
string tmpResStr = "";
int tmpRemoves = 0;
foreach (char z in resTab.ToCharArray())
{
if (z.ToString() != wrk && z.ToString() != wrk.ToLower())
{
tmpResTab += z;
}
}
tmpResStr = StringReduce(ref tmpRemoves, tmpResTab);
if (tmpResStr.Length < winner)
{
nextStr = tmpResStr;
winner = tmpResStr.Length;
wrkWin = wrk + wrk.ToLower();
}
}
}
WriteLine($"Resulterande sträng : {nextStr} , {nextStr.Length} tkn reducerad med {wrkWin}");
ReadKey();
nextStr = StringReduce(ref removes, resTab);
WriteLine($"Resulterande sträng : {nextStr} , {nextStr.Length} tkn");
ReadKey();
}
private static string StringReduce(ref int removes, string resTab)
{
int varv = 0;
string nextStr = nextLevelStr(resTab, ref removes, ref varv);
@ -43,16 +85,14 @@ namespace _2018_05
nextStr = nextLevelStr(nextStr, ref removes, ref varv);
}
WriteLine($"Resulterande sträng : {nextStr} , {nextStr.Length} tkn");
ReadKey();
return nextStr;
}
private static string nextLevelStr(string resTab,ref int removes, ref int varv)
{
string tmp = "";
removes = 0;
WriteLine($"inLängd: {resTab.Length}");
//WriteLine($"inLängd: {resTab.Length}");
foreach(char tkn in resTab.ToCharArray())
{
tmp += tkn;