fork download
  1. // A - Grid Compression
  2. #define DaAbyad ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  3. #include<bits/stdc++.h>
  4. using namespace std;
  5. const int N = 1e5 + 5, MOD = 1e9 + 7;
  6. const long long oo = 1e18 + 5;
  7. const long double pi = acos(-1);
  8. const long double eps = 1e-9;
  9. void open_file(string filename) {
  10. freopen((filename + ".in").c_str(), "r", stdin);
  11. freopen((filename + ".out").c_str(), "w", stdout);
  12. }
  13.  
  14. void Magic() {
  15. int n, m;
  16. cin >> n >> m;
  17. char a[n][m];
  18. bool goodRow[n], goodCol[m];
  19. memset(goodRow, 0, sizeof goodRow);
  20. memset(goodCol, 0, sizeof goodCol);
  21. for (int i = 0; i < n; ++i) {
  22. for (int j = 0; j < m; ++j) {
  23. cin >> a[i][j];
  24. if (a[i][j] == 'B') {
  25. goodRow[i] = true;
  26. goodCol[j] = true;
  27. }
  28. }
  29. }
  30.  
  31. for (int i = 0; i < n; ++i) {
  32. if (goodRow[i]) {
  33. for (int j = 0; j < m; ++j) {
  34. if (goodCol[j]) {
  35. cout << a[i][j];
  36. }
  37. }
  38. cout << "\n";
  39. }
  40. }
  41. }
  42.  
  43. int main() {
  44. DaAbyad
  45. int tests = 1;
  46. // cin >> tests;
  47. while (tests--) {
  48. Magic();
  49. }
  50. return 0;
  51. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Standard output is empty