finished fordulo 2
This commit is contained in:
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Program
|
||||
@@ -123,9 +124,98 @@ namespace Program
|
||||
|
||||
}
|
||||
|
||||
Console.WriteLine(new string(solvedCharsForFeladatB.ToArray()));
|
||||
|
||||
Console.WriteLine($"B feladat megoldás: {new string(solvedCharsForFeladatB.ToArray())}");
|
||||
|
||||
|
||||
// c feladat
|
||||
string atirando = "EZTKELLATIRNI";
|
||||
string pathToSzavak = @"..\..\..\Sources\szavak.txt";
|
||||
|
||||
var szavak = File.ReadAllLines(pathToSzavak);
|
||||
|
||||
Dictionary<int, char> reversedLookUpTable = new Dictionary<int, char>();
|
||||
reversedLookUpTable.Add(0, 'A');
|
||||
reversedLookUpTable.Add(1, 'E');
|
||||
reversedLookUpTable.Add(2, 'I');
|
||||
reversedLookUpTable.Add(3, 'O');
|
||||
reversedLookUpTable.Add(4, 'U');
|
||||
|
||||
List<char> titkositottKarakterek = new List<char>();
|
||||
|
||||
foreach (char c in atirando)
|
||||
{
|
||||
for (int row = 0; row < tablazat.GetLength(0); row++)
|
||||
{
|
||||
for (int col = 0; col < tablazat.GetLength(1); col++)
|
||||
{
|
||||
if (tablazat[row, col] == c)
|
||||
{
|
||||
titkositottKarakterek.Add(reversedLookUpTable[row]);
|
||||
titkositottKarakterek.Add(reversedLookUpTable[col]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
string feladatCString = new string(titkositottKarakterek.ToArray());
|
||||
Console.WriteLine(feladatCString);
|
||||
|
||||
foreach (var item in szavak)
|
||||
{
|
||||
Console.WriteLine(item);
|
||||
}
|
||||
|
||||
List<string> feladatCMegoldas = new List<string>();
|
||||
|
||||
for (int i = 0; i < feladatCString.Length; i+=2)
|
||||
{
|
||||
char firstChar = feladatCString[i];
|
||||
char secondChar = feladatCString[i + 1];
|
||||
|
||||
string pattern;
|
||||
if (firstChar == secondChar)
|
||||
{
|
||||
pattern = $@"^(?=.*{firstChar}.*{firstChar}).*{firstChar}.*{firstChar}.*$";
|
||||
}
|
||||
else
|
||||
{
|
||||
pattern = $@"^(?!.*{firstChar}.*{firstChar})(?!.*{secondChar}.*{secondChar}).*{firstChar}.*{secondChar}.*$";
|
||||
}
|
||||
Regex regex = new Regex(pattern);
|
||||
|
||||
foreach (string szo in szavak)
|
||||
{
|
||||
if (regex.IsMatch(szo))
|
||||
{
|
||||
feladatCMegoldas.Add(szo);
|
||||
//Console.WriteLine($"{firstChar} - {secondChar} - {szo}");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var item in feladatCMegoldas)
|
||||
{
|
||||
Console.Write(item + " ");
|
||||
}
|
||||
Console.WriteLine();
|
||||
|
||||
//Ellenőrzés a kapott kódra
|
||||
/*
|
||||
|
||||
List<char> solvedCharsForFeladatC = new List<char>();
|
||||
for (int i = 0; i < feladatCString.Length; i += 2)
|
||||
{
|
||||
int row = lookUpTable[feladatCString[i]];
|
||||
int col = lookUpTable[feladatCString[i + 1]];
|
||||
|
||||
solvedCharsForFeladatC.Add(tablazat[row, col]);
|
||||
|
||||
}
|
||||
|
||||
Console.WriteLine( new string(solvedCharsForFeladatC.ToArray()));
|
||||
*/
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user