#include<cstdio> #include<vector> #include<iostream> using namespace std; int main(){ int m,n; char t; vector<char> rk; vector<int> num; vector<char> col; vector<vector<char>> mapa; scanf("%d%d\n", &n, &m); mapa.push_back(vector<char>(m+1,'1')); for(int i = 1; i<n+1; i++){ mapa.push_back(vector<char>(m+1,'1')); for(int j=1; j<m+1; j++) scanf("%c", &mapa[i][j]); scanf("\n"); } bool cont = true; while(cont){ cont = false; /*** for(int i = 0; i<n+1; i++){ for(int j=0; j<m+1; j++) printf("%c ", mapa[i][j]); printf("\n"); } printf("\n");***/ for(int i = 1; i<n+1; i++){ t='0'; if(mapa[i][0] == '0') continue; bool kasuj_wiersz = true; for(int j=1; j<m+1; j++){ if (t=='0') t = mapa[i][j]; else if (mapa[i][j] != '0' and mapa[i][j] != t){ // printf("poleglem na i,j,t, map[i][j] = %d,%d,%c,%c\n", i,j,t,mapa[i][j]); kasuj_wiersz = false; break; } } if (kasuj_wiersz and t != '0'){ cont = true; rk.push_back('R'); num.push_back(i); col.push_back(t); for (int j=0; j<m+1; j++) mapa[i][j] = '0'; } } for(int i = 1; i<m+1; i++){ t='0'; if(mapa[0][i] == '0') continue; bool kasuj_kolumne = true; for(int j=1; j<n+1; j++){ if (t=='0') t = mapa[j][i]; else if (mapa[j][i] != '0' and mapa[j][i] != t){ kasuj_kolumne = false; break; } } if (kasuj_kolumne and t != '0'){ cont = true; rk.push_back('K'); num.push_back(i); col.push_back(t); for (int j=0; j<n+1; j++) mapa[j][i] = '0'; } } } printf("%ld\n", rk.size()); for(int i = rk.size()-1; i>=0; i--){ printf("%c %d %c\n", rk[i], num[i], col[i]); } }
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 | #include<cstdio> #include<vector> #include<iostream> using namespace std; int main(){ int m,n; char t; vector<char> rk; vector<int> num; vector<char> col; vector<vector<char>> mapa; scanf("%d%d\n", &n, &m); mapa.push_back(vector<char>(m+1,'1')); for(int i = 1; i<n+1; i++){ mapa.push_back(vector<char>(m+1,'1')); for(int j=1; j<m+1; j++) scanf("%c", &mapa[i][j]); scanf("\n"); } bool cont = true; while(cont){ cont = false; /*** for(int i = 0; i<n+1; i++){ for(int j=0; j<m+1; j++) printf("%c ", mapa[i][j]); printf("\n"); } printf("\n");***/ for(int i = 1; i<n+1; i++){ t='0'; if(mapa[i][0] == '0') continue; bool kasuj_wiersz = true; for(int j=1; j<m+1; j++){ if (t=='0') t = mapa[i][j]; else if (mapa[i][j] != '0' and mapa[i][j] != t){ // printf("poleglem na i,j,t, map[i][j] = %d,%d,%c,%c\n", i,j,t,mapa[i][j]); kasuj_wiersz = false; break; } } if (kasuj_wiersz and t != '0'){ cont = true; rk.push_back('R'); num.push_back(i); col.push_back(t); for (int j=0; j<m+1; j++) mapa[i][j] = '0'; } } for(int i = 1; i<m+1; i++){ t='0'; if(mapa[0][i] == '0') continue; bool kasuj_kolumne = true; for(int j=1; j<n+1; j++){ if (t=='0') t = mapa[j][i]; else if (mapa[j][i] != '0' and mapa[j][i] != t){ kasuj_kolumne = false; break; } } if (kasuj_kolumne and t != '0'){ cont = true; rk.push_back('K'); num.push_back(i); col.push_back(t); for (int j=0; j<n+1; j++) mapa[j][i] = '0'; } } } printf("%ld\n", rk.size()); for(int i = rk.size()-1; i>=0; i--){ printf("%c %d %c\n", rk[i], num[i], col[i]); } } |