Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.38 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cstdio>
  4. #include <vector>
  5. #include <string>
  6. #include <cctype>
  7. #include <iomanip>
  8. //#include <cmath>
  9. #include <iterator>
  10. #include <utility>
  11. #include <algorithm>
  12. #include <cstdlib>
  13. #include <math.h>
  14.  
  15. using namespace std;
  16.  
  17. int main()
  18. {
  19.     setlocale(LC_ALL, "Russian");
  20.     ifstream in("input.txt");
  21.     ofstream out("output.txt");
  22.     unsigned char c;
  23.     vector <vector <int> > vec(33, vector <int>(33, 0));
  24.     int counter = 0;
  25.     int last_f = -1, last_s = -1;
  26.     bool flag = false;
  27.     unsigned char first, second;
  28.     while (!in.eof())
  29.     {
  30.         in >> c;
  31.         c = tolower(c);
  32.         if (((int) ((unsigned char) ('а')) <= (int)c && (int)c <= (int) ((unsigned char) ('я'))) || ((int) c == 184))
  33.         {
  34.             if (!flag)
  35.             {
  36.                 second = c;
  37.                 flag = true;
  38.             }
  39.             else
  40.             {
  41.                 first = second;
  42.                 second = c;
  43.                 int fcode = (int)first;
  44.                 int lcode = (int)second;
  45.                 if (fcode == 184)
  46.                 {
  47.                     if (lcode == 184)
  48.                     {
  49.                         vec[0][0]++;
  50.                         last_f = 0;
  51.                         last_s = 0;
  52.                     }
  53.                     else
  54.                     {
  55.                         lcode -= 223;
  56.                         vec[0][lcode]++;
  57.                         last_f = 0;
  58.                         last_s = lcode;
  59.                     }
  60.                 }
  61.                 else
  62.                 {
  63.                     fcode -= 223;
  64.                     if (lcode == 184)
  65.                     {
  66.                         vec[fcode][0]++;
  67.                         last_f = fcode;
  68.                         last_s = 0;
  69.                     }
  70.                     else
  71.                     {
  72.                         lcode -= 223;
  73.                         vec[fcode][lcode]++;
  74.                         last_f = fcode;
  75.                         last_s = lcode;
  76.                     }
  77.                 }
  78.                 counter++;
  79.             }
  80.         }
  81.         else
  82.             flag = false;
  83.     }
  84.     if (last_f != -1)
  85.         vec[last_f][last_s]--;
  86.     int count_f = 0;
  87.     int count_s = 0;
  88.     flag = false;
  89.     vector < pair <double, string> > SortResult;
  90.     double Result;
  91.     string temp;
  92.     for(int i = 1; i < 33; i++) {
  93.         for(int j = 1; j < 33; j++) {
  94.             if(count_f == 6) {
  95.                 flag = true;
  96.                 if(count_s == 6) {
  97.                     Result = (((double)vec[0][0] / counter) * 1000) / 1000;
  98.                     temp = (unsigned char)(184);
  99.                     temp += (unsigned char)(184);
  100.                     SortResult.push_back(make_pair(Result, temp));
  101.                     j--;
  102.                 }
  103.                 else {
  104.                     Result = (((double)vec[0][j] / counter) * 1000) / 1000;
  105.                     temp = (unsigned char)(184);
  106.                     temp += (unsigned char)(j + 223);
  107.                     SortResult.push_back(make_pair(Result, temp));
  108.                 }
  109.                 count_s++;
  110.             }
  111.             else {
  112.                 if(count_s == 6) {
  113.                     Result = (((double)vec[i][0] / counter) * 1000) / 1000;
  114.                     temp = (unsigned char)(i + 223);
  115.                     temp += (unsigned char)(184);
  116.                     SortResult.push_back(make_pair(Result, temp));
  117.                 }
  118.                 else {
  119.                     Result = (((double)vec[i][j] / counter) * 1000) / 1000;
  120.                     temp = (unsigned char)(i + 223);
  121.                     temp += (unsigned char)(j + 223);
  122.                     SortResult.push_back(make_pair(Result, temp));
  123.                 }
  124.                 count_s++;
  125.             }
  126.         }
  127.         if (flag) {
  128.             i--;
  129.             flag = false;
  130.         }
  131.         count_f++;
  132.         count_s = 0;
  133.     }
  134.     sort(SortResult.begin(), SortResult.end());
  135.     for(int i = (int) SortResult.size() - 1; i >= 0; i--) {
  136.         if(SortResult[i].first != 0) {
  137.             out << SortResult[i].second << " = " << fixed << setprecision(3) << SortResult[i].first << endl;
  138.             cout << SortResult[i].second << " = " << fixed << setprecision(3) << SortResult[i].first << endl;
  139.         }
  140.     }
  141.     in.close();
  142.     out.close();
  143.     return 0;
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement