这道题让我弄会了函数中使用多维数组作参数。其实我原本想学学怎么使用变参的…… /* ID: wangqia6 TASK: transform LANG: C++ */ #include <fstream> using namespace std; char st[15][15],en[15][15],transa[15][15],transb[15][15]; int n; int check(char arr[][15], char brr[][15]) { for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) if (arr[i][j] != brr[i][j]) return 0; return 1; } void reflect(char arr[][15]) { for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) transb[i][j] = arr[i][n - 1 - j]; return; } void change90(char arr[][15]) { for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) transb[i][j] = arr[n - 1 - j][i]; return; } void change180(char arr[][15]) { for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) transb[i][j] = arr[n - 1 - i][n - 1 - j]; return; } void change270(char arr[][15]) { for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) transb[i][j] = arr[j][n - 1 - i]; return; } int main() { ifstream infile; ofstream outfile; infile.open("transform.in"); outfile.open("transform.out"); infile >> n; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) infile >> st[i][j]; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) infile >> en[i][j]; if (check(st,en)) { outfile << 2 << endl; return 0; } change90(st); if (check(transb,en)) { outfile << 1 << endl; return 0; } change180(st); if (check(transb,en)) { outfile << 2 << endl; return 0; } change270(st); if (check(transb,en)) { outfile << 3 << endl; return 0; } reflect(st); if (check(transb,en)) { outfile << 4 << endl; return 0; } for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) transa[i][j] = transb[i][j]; change90(transa); if (check(transb,en)) { outfile << 5 << endl; return 0; } change180(transa); if (check(transb,en)) { outfile << 5 << endl; return 0; } change270(transa); if (check(transb,en)) { outfile << 5 << endl; return 0; } outfile << 7 << endl; return 0; }