Aleksandr_Grigoryev

ваы

Mar 13th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.34 KB | None | 0 0
  1. ////Частотная 1
  2. #include <fstream>
  3. #include <string>
  4. using namespace std;
  5.  
  6. int main() {
  7.     ifstream input("input.txt");
  8.     ofstream output("output.txt");
  9.     string str;
  10.     getline(input, str);
  11.     const int length = 26;
  12.     int mas[length] = { 0 };
  13.     for (int i = 0; i < str.size(); i++)
  14.     {
  15.         char symb;
  16.         symb = toupper(str[i]);
  17.         if ('A'<=symb && symb <='Z')
  18.         {
  19.             mas[symb - 'A']++;
  20.         }
  21.     }
  22.     for (int i = 0; i < length; i++)
  23.     {
  24.         output << (char)(i + 'A') << "   " << mas[i] << endl;
  25.     }
  26.     return 0;
  27. }
  28.  
  29. //////////////// Частотная 2
  30. #include <fstream>
  31. #include <string>
  32. using namespace std;
  33.  
  34. int main()
  35. {
  36.     ifstream input("input.txt");
  37.     ofstream output("output.txt");
  38.     string str;
  39.     getline(input, str);
  40.     const int length = 26;
  41.     int mas[length] = { 0 };
  42.     for (int i = 0; i < str.size(); i++)
  43.     {
  44.         char symb;
  45.         symb = toupper(str[i]);
  46.         if ('A' <= symb && symb <= 'Z')
  47.         {
  48.             mas[symb - 'A']++;
  49.         }
  50.     }
  51.     int mas2[length];
  52.     for (int i = 0; i < length; i++)
  53.     {
  54.         mas2[i] = i;
  55.     }
  56.     for (int i = 0; i < length - 1; i++)
  57.     {
  58.         for (int j = 0; j < length - i - 1; j++)
  59.         {
  60.             if (mas[j] < mas[j + 1])
  61.             {
  62.                 swap(mas[j], mas[j + 1]);
  63.                 swap(mas2[j], mas2[j + 1]);
  64.             }
  65.         }
  66.     }
  67.     for (int i = 0; i < length && mas[i] != 0; i++)
  68.     {
  69.         output << (char)(mas2[i] + 'A') << "   " << mas[i] << endl;
  70.     }
  71.     return 0;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment