Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct letter{
  5. char letter;
  6. int count;
  7. };
  8.  
  9. int main()
  10. {
  11. string str;
  12. struct letter alph[28];
  13. for(int i = 0; i < 26; i++)
  14. alph[i].count = 0;
  15. char c = 'a';
  16.  
  17. for(int i = 0; i < 26; i++)
  18. alph[i].letter = c + i;
  19.  
  20. while (1)
  21. {
  22. getline(cin, str);
  23. // cout << str << endl;
  24. if (str[0] == '*')
  25. break;
  26. for (int j = 0; j < str.length(); j++)
  27. {
  28. while (str[j] != 0 && str[j] == ' ')
  29. j++;
  30. alph[str[j] - 97].count++;
  31. while (str[j] != 0 && str[j] != ' ')
  32. j++;
  33. }
  34. }
  35. struct letter temp;
  36. for(int i = 0; i < 26; i++)
  37. {
  38. for(int k = 0; k < 26 - i; k++)
  39. {
  40. if (alph[k + 1].count > alph[k].count )
  41. {
  42. temp = alph[k + 1];
  43. alph[k + 1] = alph[k];
  44. alph[k] = temp;
  45. }
  46. }
  47. }
  48.  
  49. for(int i = 0; i < 26; i++)
  50. {
  51. if (alph[i].count != 0)
  52. {
  53. cout << alph[i].letter << ' ' << alph[i].count << endl;
  54. }
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement