Andra problemet dag 5 , löst
This commit is contained in:
@ -17,7 +17,7 @@ namespace _2018_05
|
||||
//string resTab = "dabAcCaCBAcCcaDA";
|
||||
|
||||
SortedSet<Char> charset = new SortedSet<char>();
|
||||
foreach(char x in resTab.ToCharArray())
|
||||
foreach (char x in resTab.ToCharArray())
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -28,31 +28,71 @@ namespace _2018_05
|
||||
|
||||
}
|
||||
|
||||
foreach(char y in charset)
|
||||
foreach (char y in charset)
|
||||
{
|
||||
Write($"{y},");
|
||||
}
|
||||
|
||||
ReadKey();
|
||||
|
||||
int varv = 0;
|
||||
string nextStr = StringReduce(ref removes, resTab);
|
||||
|
||||
string nextStr = nextLevelStr(resTab,ref removes, ref varv);
|
||||
while (removes > 0)
|
||||
int winner = nextStr.Length;
|
||||
string wrkWin = "";
|
||||
foreach (char y in charset)
|
||||
{
|
||||
nextStr= nextLevelStr(nextStr, ref removes, ref varv);
|
||||
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);
|
||||
while (removes > 0)
|
||||
{
|
||||
nextStr = nextLevelStr(nextStr, ref removes, ref varv);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user