Advertisement
Guest User

Untitled

a guest
May 26th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 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.  
  7. namespace ConsoleApplication14
  8. {
  9. class Program
  10. {
  11. static int max = 4;
  12. struct TRozsah
  13. {
  14. public string nazev;
  15. public char c1;
  16. public char c2;
  17. public int pocet;
  18. }
  19. static TRozsah[] rozsahy = new TRozsah[max];
  20.  
  21. static void Analyzuj(string vstup)
  22. {
  23. for (int i = 0; i < max; i++) rozsahy[i].pocet=0;
  24. foreach (char c in vstup)
  25. {
  26. bool nalezeno = false;
  27. for (int i = 0; i < max; i++) if (c >= rozsahy[i].c1 && c <= rozsahy[i].c2)
  28. {
  29. rozsahy[i].pocet++;
  30. nalezeno = true;
  31. }
  32. if (!nalezeno) rozsahy[0].pocet++;
  33. }
  34. foreach (TRozsah r in rozsahy) Console.WriteLine("{0} {1}x", r.nazev,r.pocet);
  35. }
  36.  
  37. static string ZadatText(string txt)
  38. {
  39. Console.WriteLine("Zadejte text");
  40. txt =Console.ReadLine();
  41. return txt;
  42. }
  43.  
  44. static void Main(string[] args)
  45. {
  46. char volba = '0';
  47. string txt = "";
  48. rozsahy[0].nazev = "Ostatni"; rozsahy[0].c1 = ' '; rozsahy[0].c2 = ' ';
  49. rozsahy[1].nazev = "Mala pismena"; rozsahy[1].c1 = 'a'; rozsahy[1].c2 = 'z';
  50. rozsahy[2].nazev = "Velka pismena"; rozsahy[2].c1 = 'A'; rozsahy[2].c2 = 'Z';
  51. rozsahy[3].nazev = "Cislice"; rozsahy[3].c1 = '0'; rozsahy[3].c2 = '9';
  52. do
  53. {
  54. Console.Clear();
  55. if (volba == '1') txt = ZadatText(txt);
  56. if (volba == '2') Analyzuj(txt);
  57. Console.WriteLine("1..Zadat text\n2..Analyzovat text {0}\n------------\n9..Konec", txt);
  58. volba = Console.ReadKey().KeyChar;
  59. } while (volba != '0');
  60. }
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement