Advertisement
Guest User

sms szavak

a guest
Apr 18th, 2014
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.50 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.IO;
  7.  
  8. namespace sms2007
  9. {
  10. class Program
  11. {
  12. struct sms
  13. {
  14. public string szo;
  15. }
  16. static sms[] szavak = new sms[600];
  17. static int x=0;
  18. static void Main(string[] args)
  19. {
  20. string osszes = "abcdefghijklmonpqrstuvwxyz";
  21. char[] abc = new char[26];
  22. for (int i = 0; i < 26; i++)
  23. {
  24. abc[i] = osszes[i];
  25. }
  26. Console.Write("1. feladat: Adjon meg egy betűt: ");
  27. string be = Console.ReadLine();
  28. char betu = Convert.ToChar(be);
  29. for (int i = 0; i < 26; i++)
  30. {
  31. if (betu == abc[i])
  32. {
  33. if (i >= 0 && i <= 2) Console.WriteLine("2"); else { };
  34. if (i >= 3 && i <= 5) Console.WriteLine("3"); else { };
  35. if (i >= 6 && i <= 8) Console.WriteLine("4"); else { };
  36. if (i >= 9 && i <= 11) Console.WriteLine("5"); else { };
  37. if (i >= 12 && i <= 14) Console.WriteLine("6"); else { };
  38. if (i >= 15 && i <= 18) Console.WriteLine("7"); else { };
  39. if (i >= 19 && i <= 21) Console.WriteLine("8"); else { };
  40. if (i >= 22 && i <= 25) Console.WriteLine("9"); else { };
  41. }
  42. }
  43. Console.Write("2. feladat: Kérem a szót: ");
  44. string b = Console.ReadLine();
  45. string ki = "";
  46. for (int i = 0; i < b.Length; i++)
  47. {
  48. for (int j = 0; j < 26; j++)
  49. {
  50. if (b[i] == abc[j])
  51. {
  52. if (j >= 0 && j <= 2) ki+="2"; else { };
  53. if (j >= 3 && j <= 5) ki+="3"; else { };
  54. if (j >= 6 && j <= 8) ki+="4"; else { };
  55. if (j >= 9 && j <= 11) ki+="5"; else { };
  56. if (j >= 12 && j <= 14) ki+="6"; else { };
  57. if (j >= 15 && j <= 18) ki+="7"; else { };
  58. if (j >= 19 && j <= 21) ki+="8"; else { };
  59. if (j >= 22 && j <= 25) ki+="9"; else { };
  60. }
  61. }
  62. }
  63. Console.WriteLine(ki);
  64. Console.WriteLine("3. feladat: Az adatok beolvasása a szavak.txt fájlból.");
  65. StreamReader sr = new StreamReader("szavak.txt");
  66. string sor = sr.ReadLine();
  67. while (sor != null)
  68. {
  69. szavak[x].szo=sor;
  70. x++;
  71. sor = sr.ReadLine();
  72. }
  73. Console.WriteLine(x);
  74. Console.Write("4. feladat: A leghosszabb tárolt szó és hossza: ");
  75. int maxhossz = 0;
  76. string hosszuszo="";
  77. for (int i = 0; i < x; i++)
  78. {
  79. if (szavak[i].szo.Length > maxhossz) maxhossz = szavak[i].szo.Length; else { };
  80. }
  81. for (int i = 0; i < x; i++)
  82. {
  83. if (szavak[i].szo.Length == maxhossz) hosszuszo = szavak[i].szo; else { };
  84. }
  85. Console.WriteLine("{0}, {1} karakter", hosszuszo, maxhossz);
  86. Console.Write("5. feladat: Rövid szavak száma: ");
  87. int darab = 0;
  88. for (int i = 0; i < x; i++)
  89. {
  90. if (szavak[i].szo.Length <= 5) darab++; else { };
  91. }
  92. Console.WriteLine(darab);
  93. Console.WriteLine("6. feladat: Az adatok kiírása a kodok.txt állományba.");
  94. FileStream fs = new FileStream("kodok.txt", FileMode.Create);
  95. StreamWriter sw = new StreamWriter(fs);
  96. string[] szamsor = new string[x];
  97. for (int h = 0; h < x; h++)
  98. {
  99. for (int i = 0; i < szavak[h].szo.Length; i++)
  100. {
  101. for (int j = 0; j < 26; j++)
  102. {
  103. if (szavak[h].szo[i] == abc[j])
  104. {
  105. if (j >= 0 && j <= 2) szamsor[h] += "2"; else { };
  106. if (j >= 3 && j <= 5) szamsor[h] += "3"; else { };
  107. if (j >= 6 && j <= 8) szamsor[h] += "4"; else { };
  108. if (j >= 9 && j <= 11) szamsor[h] += "5"; else { };
  109. if (j >= 12 && j <= 14) szamsor[h] += "6"; else { };
  110. if (j >= 15 && j <= 18) szamsor[h] += "7"; else { };
  111. if (j >= 19 && j <= 21) szamsor[h] += "8"; else { };
  112. if (j >= 22 && j <= 25) szamsor[h] += "9"; else { };
  113. }
  114. }
  115. }
  116. }
  117. for (int i = 0; i < x; i++)
  118. {
  119. sw.WriteLine(szamsor[i]);
  120. Console.WriteLine(szamsor[i]);
  121. }
  122. Console.WriteLine(szamsor[523]);
  123. Console.Write("7. feladat: Kérem a számsort: ");
  124. string azon = Console.ReadLine();
  125. for (int i = 0; i < x; i++)
  126. {
  127. if (szamsor[i] == azon) Console.WriteLine(szavak[i].szo); else { };
  128. }
  129. sr.Close();
  130. sw.Close();
  131. fs.Close();
  132. Console.ReadKey();
  133. }
  134. }
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement