Advertisement
MaxTwain

вывод елементов строки и их сортировка the output line of el

Feb 14th, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.62 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     char str[100],str1[26];
  8.     int num[26];
  9.     int i = 0, k = 0;
  10.  
  11.     cin.getline(str, 100);
  12.     while (str[i] != '\0')
  13.     {
  14.         if (str[i] > 96 && str[i] < 123)
  15.         {
  16.             str[i]-=32;
  17.         }
  18.         if (str[i] != 32)
  19.         {
  20.             str1[k] = str[i];
  21.             k++;
  22.         }
  23.         i++;
  24.     }
  25.     cout << endl << "kol-vo znakov:  " << i << endl;
  26.     //p = i - k;
  27.     //-----------------------------------------------
  28.     for (int p = 0; p < 26; p++)
  29.     {
  30.         str1[p] = 'A' + p;
  31.     }
  32.     for (int j = 0; j < 26; j++)
  33.     {
  34.         num[j] = 0;
  35.     }
  36.     i = 0;
  37.     //-----------------------------------------------
  38.     while (str[i] != '\0')
  39.     {
  40.         for (int o = 0; o < 26; o++)
  41.         {
  42.             if (str[i] == str1[o])
  43.             {
  44.                 num[o] += 1;
  45.             }
  46.         }
  47.         i++;
  48.     }
  49.     //---------------------------------------------
  50.     for(int i = 1; i < 26; i++)
  51.     {
  52.         for(int r = 0; r < 26 - i; r++)
  53.         {
  54.             if(num[r] < num[r+1])
  55.             {
  56.                 int t = num[r];
  57.                 num[r] = num[r+1];
  58.                 num[r+1] = t;
  59.                 //----------------
  60.                 int l = str1[r];
  61.                 str1[r] = str1[r+1];
  62.                 str1[r+1] = l;
  63.             }
  64.         }
  65.     }
  66.     //---------------------------------------------
  67.     for (int j = 0; j < 26; j++)
  68.     {
  69.         if (num[j] > 0)
  70.         {
  71.             cout << "'" << str1[j] << "'" << "-" << num[j] << endl;
  72.         }
  73.     }
  74.     return 0;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement