Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 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.  
  44. int fel;
  45. sorok[i] = probKarEltav(sorok[i]);
  46. int utolsoKarPoz = sorok[i].Length-1;
  47. fel = sorok[i].Length / 2 ;
  48. int j = 0;
  49. pali = true;
  50. while (pali && j < fel)
  51. {
  52. if(sorok[i][j] != sorok[i][utolsoKarPoz-j])
  53. {
  54. pali = false;
  55. }
  56. j++;
  57. }
  58. if (pali)
  59. {
  60. Console.WriteLine("Palindrom");
  61. }
  62. else
  63. {
  64. Console.WriteLine("Nem palindrom");
  65. }
  66.  
  67. }
  68.  
  69.  
  70.  
  71.  
  72. sr.Close();
  73.  
  74.  
  75. Console.ReadKey();
  76. }
  77.  
  78. static bool betuE(char c)
  79. {
  80. char[] problemak = new char[] { ',', '.', '!', '?', '-', ' ' };
  81. for (int i = 0; i < problemak.Length; i++)
  82. {
  83. if (problemak[i] == c)
  84. {
  85. return false;
  86. }
  87.  
  88. }
  89. return true;
  90. }
  91.  
  92. static string probKarEltav(string s)
  93. {
  94.  
  95.  
  96. string temp = "";
  97. foreach (char c in s)
  98. {
  99.  
  100. if (betuE(c))
  101. {
  102.  
  103. temp += char.ToLower(c);
  104. }
  105. }
  106.  
  107. Console.WriteLine(temp);
  108. return temp;
  109.  
  110. }
  111. }
  112.  
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement