Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace ConsoleApp7
  9. {
  10. class Program
  11. {
  12. static void Main(string[] args)
  13. {
  14.  
  15. List<string> sorok = new List<string>();
  16. //Beolvasás fájlból
  17. StreamReader sr = new StreamReader("pali.txt");
  18. while (!sr.EndOfStream)
  19. {
  20. sorok.Add(sr.ReadLine());
  21. Console.WriteLine(sorok[sorok.Count - 1]);
  22.  
  23. }
  24. Console.WriteLine("Sorok száma: " + sorok.Count);
  25. //Feldolgozás
  26. //Problémás karakterek: , . ! ? szóköz -
  27. //char.IsLetter
  28.  
  29. //betue függvény tesztelése
  30. if (betuE('a'))
  31. {
  32. Console.WriteLine("Betű");
  33. }
  34. else
  35. {
  36. Console.WriteLine("Nem betű");
  37. }
  38.  
  39. bool pali = true;
  40.  
  41. for (int i = 0; i < sorok.Count; i++)
  42. {
  43. int fel;
  44. sorok[i] = probKarEltav(sorok[i]);
  45. int utolsoKarPoz = sorok[i].Length -1;
  46. fel = sorok[i].Length / 2;
  47. int j = 0;
  48. pali = true;
  49. while (pali && j < fel);
  50. {
  51. if (sorok[i][j] != sorok[i][utolsoKarPoz - j])
  52. {
  53. pali = false;
  54. }
  55. j++;
  56. }
  57. if (pali)
  58. {
  59. Console.WriteLine("Palindrom");
  60. }
  61. else
  62. {
  63. Console.WriteLine("Nem palindrom");
  64. }
  65. }
  66.  
  67.  
  68.  
  69.  
  70. sr.Close();
  71.  
  72.  
  73. Console.ReadKey();
  74. }
  75.  
  76. static bool betuE(char c)
  77. {
  78. char[] problemak = new char[] { ',', '.', '!', '?', '-', ' ' };
  79. for (int i = 0; i < problemak.Length; i++)
  80. {
  81. if (problemak[i] == c)
  82. {
  83. return false;
  84. }
  85.  
  86. }
  87. return true;
  88. }
  89.  
  90. static string probKarEltav(string s)
  91. {
  92.  
  93.  
  94. string temp = "";
  95. foreach (char c in s)
  96. {
  97.  
  98. if (betuE(c))
  99. {
  100.  
  101. temp += char.ToLower(c);
  102. }
  103. }
  104.  
  105. Console.WriteLine(temp);
  106. return temp;
  107.  
  108. }
  109. }
  110.  
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement