fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int R, C;
  6. cin >> R >> C;
  7. vector<string> board(R);
  8. for (int i = 0; i < R; i++) {
  9. cin >> board[i];
  10. }
  11.  
  12. bool changed = true;
  13. while (changed) {
  14. changed = false;
  15.  
  16. // Step 1: Hapus baris yang penuh
  17. vector<string> newBoard;
  18. for (int i = 0; i < R; i++) {
  19. if (count(board[i].begin(), board[i].end(), '1') != C) {
  20. newBoard.push_back(board[i]);
  21. } else {
  22. changed = true; // baris penuh ditemukan
  23. }
  24. }
  25.  
  26. // Tambahkan baris kosong di atas sebanyak baris yang dihapus
  27. while ((int)newBoard.size() < R) {
  28. newBoard.insert(newBoard.begin(), string(C, '0'));
  29. }
  30.  
  31. board = newBoard;
  32. }
  33.  
  34. // Cetak hasil akhir
  35. for (int i = 0; i < R; i++) {
  36. cout << board[i] << endl;
  37. }
  38.  
  39. return 0;
  40. }
Success #stdin #stdout 0.01s 5288KB
stdin
6 3
110
110
100
110
111
110
stdout
000
110
110
100
110
110