188 lines
5.5 KiB
C#
188 lines
5.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.IO;
|
|
using System.Text.RegularExpressions;
|
|
|
|
public static class Karakterek
|
|
{
|
|
public static List<char> KarakterekList = new List<char>();
|
|
public static void ReadDataFromFile(string path)
|
|
{
|
|
KarakterekList = File.ReadAllText(path).ToCharArray().ToList();
|
|
}
|
|
|
|
public static List<char> LongestStringWithTwoCharactersOnly()
|
|
{
|
|
if (KarakterekList.Count < 2)
|
|
return new List<char>();
|
|
|
|
List<char> currentBestCharacterSequence = new List<char>();
|
|
List<char> currentCharacterSequence = new List<char>();
|
|
|
|
char firstChar = KarakterekList[0];
|
|
char secondChar = KarakterekList[1];
|
|
|
|
currentCharacterSequence.Add(firstChar);
|
|
currentCharacterSequence.Add(secondChar);
|
|
|
|
for (int i = 2; i < KarakterekList.Count; i++)
|
|
{
|
|
char item = KarakterekList[i];
|
|
|
|
if (item == firstChar || item == secondChar)
|
|
{
|
|
currentCharacterSequence.Add(item);
|
|
}
|
|
else
|
|
{
|
|
if (currentCharacterSequence.Count > currentBestCharacterSequence.Count)
|
|
{
|
|
currentBestCharacterSequence = new List<char>(currentCharacterSequence);
|
|
}
|
|
|
|
firstChar = currentCharacterSequence[currentCharacterSequence.Count - 1];
|
|
secondChar = item;
|
|
|
|
currentCharacterSequence.Clear();
|
|
currentCharacterSequence.Add(firstChar);
|
|
currentCharacterSequence.Add(secondChar);
|
|
}
|
|
}
|
|
|
|
if (currentCharacterSequence.Count > currentBestCharacterSequence.Count)
|
|
{
|
|
currentBestCharacterSequence = currentCharacterSequence;
|
|
}
|
|
|
|
return currentBestCharacterSequence;
|
|
}
|
|
|
|
public static int CountABCSequences(string input)
|
|
{
|
|
int count = 0;
|
|
for (int i = 0; i < input.Length; i++)
|
|
{
|
|
if (input[i] == 'a')
|
|
{
|
|
for (int j = i + 1; j < input.Length; j++)
|
|
{
|
|
if (input[j] == 'b')
|
|
{
|
|
for (int k = j + 1; k < input.Length; k++)
|
|
{
|
|
if (input[k] == 'c')
|
|
{
|
|
count++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return count;
|
|
}
|
|
|
|
public static int TotalDistanceTraveled(string input){
|
|
int x = 0;
|
|
int y = 0;
|
|
|
|
for (int i = 0; i < input.Length; i++)
|
|
{
|
|
if (input[i] == 'b')
|
|
{
|
|
x++;
|
|
}
|
|
else if (input[i] == 'd')
|
|
{
|
|
x--;
|
|
}
|
|
else if (input[i] == 'a')
|
|
{
|
|
y++;
|
|
}
|
|
else if (input[i] == 'c')
|
|
{
|
|
y--;
|
|
}
|
|
}
|
|
return (int)Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2));
|
|
}
|
|
}
|
|
|
|
public static class Szoveg{
|
|
public static List<string> fullTextInListOfString = new List<string>();
|
|
public static List<string> wordsWithUniqeCharactersOnly = new List<string>();
|
|
|
|
|
|
public static void ReadDataFromFile(string path)
|
|
{
|
|
var lines = File.ReadAllText(path).Split(new string[] { Environment.NewLine }, StringSplitOptions.None).ToList();
|
|
|
|
foreach (var line in lines)
|
|
{
|
|
var allStringsInLine = line.Split(' ');
|
|
foreach (var str in allStringsInLine)
|
|
{
|
|
fullTextInListOfString.Add(str);
|
|
}
|
|
}
|
|
}
|
|
|
|
public static List<string> WordsWithUniqeCharactersOnly()
|
|
{
|
|
foreach (var word in fullTextInListOfString)
|
|
{
|
|
if (word.Distinct().Count() == word.Length)
|
|
{
|
|
wordsWithUniqeCharactersOnly.Add(word);
|
|
}
|
|
}
|
|
|
|
return wordsWithUniqeCharactersOnly;
|
|
}
|
|
|
|
public static string LongestStringWithUniqueCharacters()
|
|
{
|
|
return wordsWithUniqeCharactersOnly.OrderByDescending(s => s.Length).First();
|
|
}
|
|
}
|
|
|
|
public class Program
|
|
{
|
|
public static void Main(string[] args)
|
|
{
|
|
Karakterek.ReadDataFromFile(@"..\karsor.txt");
|
|
|
|
//System.Console.WriteLine($"{Karakterek.KarakterekList.Count}");
|
|
|
|
// feladat 1 a
|
|
/*
|
|
var longestStringWithTwoCharactersOnly = Karakterek.LongestStringWithTwoCharactersOnly();
|
|
var karakterek = longestStringWithTwoCharactersOnly.Distinct().OrderBy(c => c).ToArray();
|
|
int longestStringWithTwoCharactersOnlyLength = longestStringWithTwoCharactersOnly.Count;
|
|
|
|
System.Console.WriteLine($"{karakterek[0]}{karakterek[1]}{longestStringWithTwoCharactersOnlyLength}");
|
|
*/
|
|
|
|
// feladat 1 b
|
|
|
|
// ez az input változó volt használva a b és a c részben is
|
|
//string input = new string(Karakterek.KarakterekList.ToArray());
|
|
|
|
//System.Console.WriteLine($"{Karakterek.CountABCSequences(input)}");
|
|
|
|
// feladat 1 c
|
|
//System.Console.WriteLine($"{Karakterek.TotalDistanceTraveled(input)}");
|
|
|
|
// feladat 2 a
|
|
|
|
Szoveg.ReadDataFromFile(@"..\szoveg.txt");
|
|
|
|
Szoveg.wordsWithUniqeCharactersOnly = Szoveg.WordsWithUniqeCharactersOnly();
|
|
|
|
System.Console.WriteLine($"{Szoveg.LongestStringWithUniqueCharacters()}");
|
|
|
|
}
|
|
} |