Advertisement
Lucky134Lucky

Untitled

Feb 28th, 2016
78
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. int getindexFromChar (char d) {
  5. int w = -1;
  6.  
  7. if ( d >= 'A' && d <= 'Z' )
  8. w = d - 65;
  9.  
  10. return w;
  11. }
  12. int main()
  13. {
  14. int index[256] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25};
  15. int frequency[256] { };
  16. char stroka[100];
  17.  
  18. cout << "Vvedite stroku: ";
  19. cin.getline(stroka, 100);
  20.  
  21. char k = ' ';
  22. int z = 0;
  23.  
  24.  
  25.  
  26. int d = 0;
  27.  
  28. while(stroka[d]) {
  29.  
  30. k = stroka[d];
  31.  
  32. if ( k >= 'a' && k <= 'z')
  33. k -= 32;
  34.  
  35.  
  36. frequency[getindexFromChar(k)]++;
  37.  
  38. d++;
  39. }
  40.  
  41. int length = 26;
  42.  
  43. for(int i = 0; i < length - 1; i++){
  44.  
  45. for(int n = 0; n < length - i - 1; n++) {
  46.  
  47. if(frequency[index[n]] < frequency[index[n+1]]) {
  48.  
  49.  
  50. char d = index[n];
  51. index[n] = index[n+1];
  52. index[n+1] = d;
  53.  
  54. }
  55. }
  56. }
  57.  
  58. int c = 0;
  59.  
  60. while(frequency[index[c]]) {
  61. char f = index[c]+65;
  62. cout << f << " - " << frequency[index[c]];
  63. cout<<endl;
  64. c++;
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement