Advertisement
Guest User

Untitled

a guest
Nov 14th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <cctype>
  4. #include <limits>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10. char literyM[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
  11. char literyD[26] = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
  12. int wystapieniaM[26]={0};
  13. int wystapieniaD[26]={0};
  14.  
  15. int n;
  16. string tekst;
  17. cout<<"Prosze podac liczbe wierszy tekstu:"<<endl;
  18. cin>>n;
  19. cin.ignore( numeric_limits < streamsize >::max(), '\n' );
  20. if (n>150)
  21. {
  22. cout<<"Liczba wierszy tekstu nie moze przekraczac 150 wierszy"<<endl;
  23. main();
  24. }
  25. for (int z=0;z<n;z++)
  26. {
  27. cout<<"Prosze podac tekst do zliczenia liter:"<<endl;
  28. getline(cin,tekst);
  29. int dlugosc = tekst.length();
  30. for (int i=0; i<=dlugosc;i++)
  31. {
  32. if (islower(tekst[i]))
  33. {
  34. for (int m=0;m<=26;m++)
  35. {
  36. if (tekst[i] == literyM[m])
  37. {
  38. wystapieniaM[m]++;
  39. }
  40. }
  41. }
  42. if (isupper(tekst[i]))
  43. {
  44. for (int d=0;d<=26;d++)
  45. {
  46. if (tekst[i] == literyD[d])
  47. {
  48. wystapieniaD[d]++;
  49. }
  50. }
  51. }
  52. }
  53. }
  54.  
  55. for (int wM=0;wM<26;wM++)
  56. {
  57. if (wystapieniaM[wM] > 0)
  58. {
  59. cout<<literyM[wM]<<" "<<wystapieniaM[wM]<<endl;
  60. }
  61. }
  62. for (int wD=0;wD<26;wD++)
  63. {
  64. if (wystapieniaD[wD] > 0)
  65. {
  66. cout<<literyD[wD]<<" "<<wystapieniaD[wD]<<endl;
  67. }
  68. }
  69. return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement