Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- int main(){
- int t; cin >> t;
- while(t--){
- int n; cin >> n;
- int a[n][n], i, j;
- // Taking Input
- for(i = 0; i < n; i++){
- for(j = 0; j < n; j++){
- cin >> a[i][j];
- }
- }
- int row[n] = {1}, col[n] = {1};
- for(i = 0; i < n; i++){
- row[i] = 1;
- col[i] = 1;
- }
- for(i = 0; i < n; i++){
- for(j = 0; j < n; j++){
- if(a[i][j] == 0){
- row[i] = 0;
- col[j] = 0;
- }
- }
- }
- for(i = 0; i < n; i++){
- for(j = 0; j < n; j++){
- if(row[i] == 0 || col[j] == 0){
- a[i][j] = 0;
- }
- }
- }
- // Showing result
- for(i = 0; i < n; i++){
- for(j = 0; j < n; j++){
- cout << a[i][j] << ' ';
- }
- }
- cout << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement