Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- #include <algorithm>
- int main()
- {
- using namespace std;
- size_t n;
- cin >> n;
- cin.ignore();
- string line, glitches;
- vector<string> matrix;
- vector<pair<size_t, size_t>> positions;
- for (size_t i = 0; i < n; ++i)
- {
- getline(cin, line);
- matrix.push_back(line);
- size_t pos = 0;
- while((pos = line.find_first_not_of('.', pos)) != string::npos)
- {
- char ch = line[pos];
- if (glitches.find(ch) == string::npos)
- {
- glitches += ch;
- positions.push_back(make_pair(i,pos));
- }
- pos++;
- }
- }
- for (size_t i=0; i<glitches.length(); ++i)
- {
- size_t max_num = 1, num, row = positions[i].first + 1;
- while ((num = count(matrix[row].begin(), matrix[row].end(), glitches[i])) > max_num)
- {
- max_num = num;
- row++;
- }
- positions[i].first = row - 1;
- //cout << glitches[i] << ' ' << positions[i].first << ',' << positions[i].second << endl;
- }
- string dots(n, '.');
- matrix.assign(n, dots);
- for (size_t i = 0; i < glitches.length(); ++i)
- matrix[positions[i].first][positions[i].second] = glitches[i];
- for (const string& str : matrix)
- cout << str << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement