Advertisement
STANAANDREY

T pb12/66

Oct 5th, 2019
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.21 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. #include <stdio.h>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     int nrlet = 'z' - 'a' + 1, fr[nrlet], mini = 256, maxi = 0;
  9.     char s[256], cmini, cmaxi;
  10.     gets(s);
  11.  
  12.     for (int i = 0; i < nrlet; i++)
  13.         fr[i] = 0;
  14.  
  15.     for (int i = 0; s[i]; i++)
  16.     {
  17.         if ('A' <= s[i] && s[i] <= 'Z')
  18.             s[i] += ' ';
  19.  
  20.         fr[s[i] - 'a']++;
  21.     }
  22.  
  23.     for (int i = 0; i < nrlet; i++)
  24.     {
  25.         if (mini > fr[i] && fr[i])
  26.         {
  27.             cmini = char(i) + 'a';
  28.             mini = fr[i];
  29.         }
  30.  
  31.         if (maxi < fr[i])
  32.         {
  33.             cmaxi = char(i) + 'a';
  34.             maxi = fr[i];
  35.         }
  36.     }
  37.  
  38.     for (int i = 0; i < nrlet - 1; i++)
  39.         for (int j = i + 1; j < nrlet; j++)
  40.             if (fr[i] > fr[j])
  41.             {
  42.                 int aux;
  43.                 aux = fr[i];
  44.                 fr[i] = fr[j];
  45.                 fr[j] = aux;
  46.             }
  47.  
  48.     cout << "aparitii: ";
  49.     for (int i = 0; i < nrlet; i++)
  50.         if (fr[i])
  51.             cout << fr[i] << ' ';
  52.     cout << endl;
  53.  
  54.     cout << "litera cu aparitii minime: " << cmini << endl;
  55.     cout << "litera cu aparitii maxime: " << cmaxi;
  56.  
  57.     return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement