fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <map>
  4. #include <algorithm>
  5. #include <set>
  6. using namespace std;
  7. typedef long long ll;
  8.  
  9. int main() {
  10. ll t;
  11. cin >> t;
  12. while(t--){
  13. int n;
  14. cin >> n;
  15. vector<vector<char> > v(n+1, vector<char>(n+1));
  16. vector<int> sum(n+1, 0), ans(n, 0);
  17. for(int i = 1; i <= n; i++){
  18. for(int j = 1; j <= n; j++){
  19. cin >> v[i][j];
  20. if(v[i][j] == '1' && i > j || v[i][j] == '0' && i < j){
  21. sum[i]++;
  22. }
  23. }
  24. }
  25. for(int i = 1; i <= n; i++){
  26. ans[sum[i]] = i;
  27. }
  28. for(auto u: ans)cout << u << " ";
  29. cout << endl;
  30. }
  31. }
Success #stdin #stdout 0s 5288KB
stdin
3
1
0
5
00101
00101
11001
00001
11110
6
000000
000000
000000
000000
000000
000000
stdout
1 
4 2 1 3 5 
6 5 4 3 2 1