SHARE
TWEET

Glitches C++

kolioi Jan 4th, 2019 140 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top