Advertisement
Guest User

Untitled

a guest
Feb 20th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.84 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 ConsoleApplication33
  9. {
  10. class Program
  11. {
  12. static int[] zjistiSamohlasky(char[] znaky, string text)
  13. {
  14. int[] stav = new int[znaky.Length];
  15. int pocet1 = 0;
  16. for (int i = 0; i < znaky.Length; i++)
  17. {
  18. foreach (char c in text)
  19. if (Convert.ToString(znaky[i]).Contains(c))
  20. {
  21.  
  22. if (i == pocet1)
  23. stav[pocet1]++;
  24. }
  25. pocet1++;
  26. }
  27. return stav;
  28.  
  29.  
  30. }
  31. static void Main(string[] args)
  32. {
  33. bool pokr = true;
  34.  
  35.  
  36.  
  37. string text = "";
  38. string cesta = "";
  39. bool plati = true;
  40. Console.WriteLine("Zadej cestu k souboru");
  41.  
  42. cesta = Console.ReadLine();
  43.  
  44. while (pokr)
  45.  
  46. {
  47. Console.WriteLine("zvol operaci!");
  48. Console.WriteLine("------------------------");
  49. Console.WriteLine("-samo- pro vyhledani aeiou");
  50. Console.WriteLine("------------------------");
  51. Console.WriteLine("-vyhl- pro vlastni vyber");
  52. Console.WriteLine("------------------------");
  53. Console.WriteLine("-cel- pro soucet vsech");
  54. Console.WriteLine("------------------------");
  55. Console.WriteLine("-vyp- pro vypsani pohadky");
  56. Console.WriteLine("------------------------");
  57. Console.WriteLine("-zap- pro zapsani do pohadky");
  58. Console.WriteLine("------------------------");
  59. Console.WriteLine("-maz- pro smaazani obsahu souboru");
  60. Console.WriteLine("------------------------");
  61.  
  62. string samohlasky = "";
  63. bool chce = true;
  64. string operace = Console.ReadLine();
  65. switch (operace)
  66. {
  67. case "samo":
  68. samohlasky = "aeiou";
  69. using (StreamReader nr = new StreamReader(cesta))
  70. {
  71.  
  72.  
  73.  
  74.  
  75. text = nr.ReadToEnd();
  76. nr.Close();
  77. }
  78. break;
  79. case "vyhl":
  80. Console.WriteLine("Zadej znaky, ktere chces analyzovat, bez mezer - format abcd");
  81. samohlasky = Console.ReadLine();
  82. break;
  83. case "cel":
  84. Console.WriteLine(zjistiSamohlasky("aeiou".ToArray(), text).Sum());
  85. chce = false;
  86. break;
  87.  
  88. default:
  89. Console.WriteLine("Nezvolili jste zadnou volbu. Prejete si program ukoncit? Jednicku pro ano cokoliv jineho - ne");
  90. if (Console.ReadLine() != "1")
  91.  
  92. Environment.Exit(0);
  93. else chce = false;
  94. break;
  95. case "vyp":
  96.  
  97. try
  98. {
  99. using (StreamReader nr = new StreamReader(cesta))
  100. {
  101.  
  102.  
  103.  
  104.  
  105. text = nr.ReadToEnd();
  106. nr.Close();
  107. }
  108. plati = false;
  109. }
  110. catch (Exception ex)
  111. {
  112. Console.ForegroundColor = ConsoleColor.Red;
  113. Console.WriteLine(ex.Message);
  114. Console.ResetColor();
  115. plati = true;
  116.  
  117. }
  118. chce = false;
  119. Console.WriteLine(text);
  120. break;
  121. case "zap":
  122. //using (StreamWriter nc = new StreamWriter(cesta))
  123. //{
  124.  
  125. // n
  126. // nc.Close();
  127. //}
  128. Console.WriteLine("Zadej, co chces pripsat");
  129. using (StreamWriter w = File.AppendText(cesta))
  130. {
  131. w.WriteLine(Console.ReadLine());
  132. }
  133. chce = false;
  134. break;
  135.  
  136. case "maz":
  137. using (var fs = new FileStream(@cesta, FileMode.Truncate))
  138. {
  139. fs.Close();
  140. }
  141. chce = false;
  142. break;
  143.  
  144.  
  145.  
  146. }
  147.  
  148. int pocet = 0;
  149.  
  150. char[] znaky = samohlasky.ToArray();
  151. if (chce)
  152. {
  153.  
  154. Console.WriteLine("Pocet znaku:");
  155.  
  156. for (int i = 0; i < znaky.Length; i++)
  157.  
  158. Console.WriteLine("{0}: {1}", znaky[i], zjistiSamohlasky(znaky, text)[i]);
  159. }
  160. Console.WriteLine("Chces pokracovat? Dej 1 jinak cokoliv jineho");
  161. if (Console.ReadLine() != "1")
  162. pokr = false;
  163. else Console.Clear();
  164.  
  165. }
  166. }
  167. }
  168. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement