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