【思路】:需要用手写一下。如下图一目了然。
【AC代码】:
#include <iostream> #include <algorithm> #include <iomanip> #include <cstdio> #include <cstring> using namespace std; #define MAX 20+2 int test[MAX][MAX]; char str[MAX][MAX]; int cnt[MAX]; int main() { //freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout); int n = 0, i = 0, j = 0; //input cin >> n; if (2 == n) { cout << 1 << " " << 2; return 0; } for (i = 0; i < n; i++) { for (j = 0; j < n; j++) cin >> test[i][j]; } //trans for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { str[i][j] = test[i][j]+'0'; } str[i][j] = '\0'; } //cnt for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { if (!strcmp(str[i], str[j])) cnt[i]++; } } //output int max = -1, pos = -1; for (i = 0; i < n; i++) { if (cnt[i] > max) { max = cnt[i]; pos = i; } } for (i = 0; i < n; i++) if ('1' == str[pos][i]) cout << i+1<< " "; }
时间: 2024-11-13 11:25:16