Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- #include <map>
- #include <set>
- #include <algorithm>
- using namespace std;
- int main() {
- int matrixSize;
- cin >> matrixSize;
- cin.ignore();
- set<char> fixed;
- map<char, vector<int>> bugs;
- vector<vector<char>> matrix(matrixSize, vector<char>(matrixSize, '.'));
- string line;
- char bug;
- for (int r = 0; r < matrixSize; r++) {
- getline(cin, line);
- for (int c = 0; c < matrixSize; c++) {
- bug = line[c];
- if (bug != '.') {
- if (fixed.find(bug) == fixed.end()) {
- if (bugs.find(bug) == bugs.end()) {
- bugs[bug] = { 1, c };
- }
- else {
- int counter = count(line.begin(), line.end(), bug);
- if (bugs[bug][0] <= counter) {
- bugs[bug][0] = counter;
- }
- else {
- matrix[r - 1][bugs[bug][1]] = bug;
- fixed.insert(bug);
- }
- }
- }
- }
- }
- }
- for (int r = 0; r < matrixSize; r++) {
- for (int c = 0; c < matrixSize; c++) {
- cout << matrix[r][c];
- }
- cout << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement