Advertisement
Lucky134Lucky

Untitled

Feb 21st, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. char index[256];
  8. int frequency[256] { };
  9. char stroka[100];
  10.  
  11. cout << "Vvedite stroku: ";
  12. cin.getline(stroka, 100);
  13.  
  14. char k = ' ';
  15. int z = 0;
  16.  
  17. while ( k != 0) {
  18. k = stroka[z];
  19.  
  20. if ( k >= 'a' && k <= 'z') {
  21. stroka[z] -= 32;
  22. }
  23.  
  24. z++;
  25. }
  26.  
  27. int d = 0;
  28.  
  29. while(stroka[d]) {
  30.  
  31. index[stroka[d]-65] = stroka[d];
  32. frequency[stroka[d]-65]++;
  33.  
  34. d++;
  35. }
  36.  
  37. int length = 26;
  38.  
  39. for(int i = 0; i < length - 1; i++){
  40.  
  41. for(int n = 0; n < length - i - 1; n++) {
  42.  
  43. if(frequency[n] < frequency[n+1]) {
  44.  
  45. int b = frequency[n];
  46. frequency[n] = frequency[n+1];
  47. frequency[n+1] = b;
  48.  
  49. char d = index[n];
  50. index[n] = index[n+1];
  51. index[n+1] = d;
  52.  
  53. }
  54. }
  55. }
  56.  
  57. int c = 0;
  58.  
  59. while(frequency[c]) {
  60. cout << index[c] << " - " << frequency[c];
  61. cout << endl;
  62.  
  63. c++;
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement