Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApp7
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<string> sorok = new List<string>();
- //Beolvasás fájlból
- StreamReader sr = new StreamReader("pali.txt");
- while (!sr.EndOfStream)
- {
- sorok.Add(sr.ReadLine());
- Console.WriteLine(sorok[sorok.Count - 1]);
- }
- Console.WriteLine("Sorok száma: " + sorok.Count);
- //Feldolgozás
- //Problémás karakterek: , . ! ? szóköz -
- //char.IsLetter
- //betue függvény tesztelése
- if (betuE('a'))
- {
- Console.WriteLine("Betű");
- }
- else
- {
- Console.WriteLine("Nem betű");
- }
- bool pali = true;
- for (int i = 0; i < sorok.Count; i++)
- {
- int fel;
- sorok[i] = probKarEltav(sorok[i]);
- int utolsoKarPoz = sorok[i].Length -1;
- fel = sorok[i].Length / 2;
- int j = 0;
- pali = true;
- while (pali && j < fel);
- {
- if (sorok[i][j] != sorok[i][utolsoKarPoz - j])
- {
- pali = false;
- }
- j++;
- }
- if (pali)
- {
- Console.WriteLine("Palindrom");
- }
- else
- {
- Console.WriteLine("Nem palindrom");
- }
- }
- sr.Close();
- Console.ReadKey();
- }
- static bool betuE(char c)
- {
- char[] problemak = new char[] { ',', '.', '!', '?', '-', ' ' };
- for (int i = 0; i < problemak.Length; i++)
- {
- if (problemak[i] == c)
- {
- return false;
- }
- }
- return true;
- }
- static string probKarEltav(string s)
- {
- string temp = "";
- foreach (char c in s)
- {
- if (betuE(c))
- {
- temp += char.ToLower(c);
- }
- }
- Console.WriteLine(temp);
- return temp;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement