Advertisement
kolioi

Glitches C++

Jan 4th, 2019
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.18 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <algorithm>
  5.  
  6. int main()
  7. {
  8.     using namespace std;
  9.  
  10.     size_t n;
  11.     cin >> n;
  12.  
  13.     cin.ignore();
  14.  
  15.     string line, glitches;
  16.     vector<string> matrix;
  17.     vector<pair<size_t, size_t>> positions;
  18.     for (size_t i = 0; i < n; ++i)
  19.     {
  20.         getline(cin, line);
  21.         matrix.push_back(line);
  22.         size_t pos = 0;
  23.         while((pos = line.find_first_not_of('.', pos)) != string::npos)
  24.         {
  25.             char ch = line[pos];
  26.             if (glitches.find(ch) == string::npos)
  27.             {
  28.                 glitches += ch;
  29.                 positions.push_back(make_pair(i,pos));
  30.             }
  31.             pos++;
  32.         }
  33.     }
  34.  
  35.     for (size_t i=0; i<glitches.length(); ++i)
  36.     {
  37.         size_t max_num = 1, num, row = positions[i].first + 1;
  38.         while ((num = count(matrix[row].begin(), matrix[row].end(), glitches[i])) > max_num)
  39.         {
  40.             max_num = num;
  41.             row++;
  42.         }
  43.         positions[i].first = row - 1;
  44.         //cout << glitches[i] << ' ' << positions[i].first << ',' << positions[i].second << endl;
  45.     }
  46.  
  47.     string dots(n, '.');
  48.     matrix.assign(n, dots);
  49.     for (size_t i = 0; i < glitches.length(); ++i)
  50.         matrix[positions[i].first][positions[i].second] = glitches[i];
  51.  
  52.     for (const string& str : matrix)
  53.         cout << str << endl;
  54.  
  55.     return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement