#include<iostream> #include<stack> std::stack<std::pair<char, std::pair<int, char> > > s; char arr[2005][2005]; int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0); int n, m, k; std::cin >> n >> m; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { std::cin >> arr[i][j]; } } // poziome int sw = -1; while (s.size() != sw) { sw = s.size(); for (int i = 0; i < n; i++) { bool f = false; char c; int j; for (j = 1; j < m; j++) { if (!f && arr[i][j] != '-') { f = true; c = arr[i][j]; } if (f) { if (arr[i][j] == c || arr[i][j] == '-') { continue; } else { break; } } } if (j == m && f) { s.push({ 'R',{i,c} }); for (int j = 0; j < m; j++) { arr[i][j] = '-'; } // goto end; // std::cout <<"W "<< i << '\n'; } } //pionowe for (int i = 0; i < m; i++) { bool f = false; char c; int j; for (j = 0; j < n; j++) { if (!f && arr[j][i] != '-') { f = true; c = arr[j][i]; } if (f) { if (arr[j][i] == c || arr[j][i] == '-') { continue; } else { break; } } } if (j == n && f) { s.push({ 'K',{i,c} }); for (int j = 0; j < n; j++) { arr[j][i] = '-'; } // goto end; //std::cout <<"K "<< i << '\n'; } } //end: //int wzk; } std::cout << s.size() << '\n'; while (!s.empty()) { std::cout << s.top().first << " " << s.top().second.first + 1<< " " << s.top().second.second << '\n'; s.pop(); } }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | #include<iostream> #include<stack> std::stack<std::pair<char, std::pair<int, char> > > s; char arr[2005][2005]; int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0); int n, m, k; std::cin >> n >> m; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { std::cin >> arr[i][j]; } } // poziome int sw = -1; while (s.size() != sw) { sw = s.size(); for (int i = 0; i < n; i++) { bool f = false; char c; int j; for (j = 1; j < m; j++) { if (!f && arr[i][j] != '-') { f = true; c = arr[i][j]; } if (f) { if (arr[i][j] == c || arr[i][j] == '-') { continue; } else { break; } } } if (j == m && f) { s.push({ 'R',{i,c} }); for (int j = 0; j < m; j++) { arr[i][j] = '-'; } // goto end; // std::cout <<"W "<< i << '\n'; } } //pionowe for (int i = 0; i < m; i++) { bool f = false; char c; int j; for (j = 0; j < n; j++) { if (!f && arr[j][i] != '-') { f = true; c = arr[j][i]; } if (f) { if (arr[j][i] == c || arr[j][i] == '-') { continue; } else { break; } } } if (j == n && f) { s.push({ 'K',{i,c} }); for (int j = 0; j < n; j++) { arr[j][i] = '-'; } // goto end; //std::cout <<"K "<< i << '\n'; } } //end: //int wzk; } std::cout << s.size() << '\n'; while (!s.empty()) { std::cout << s.top().first << " " << s.top().second.first + 1<< " " << s.top().second.second << '\n'; s.pop(); } } |