密码(Password)
1 #include<cstdio> 2 #include<cstring> 3 using namespace std; 4 int k, cnt; 5 char G[2][6][5], ans[6]; 6 bool dfs(int col){ 7 if (col == 5){ 8 if (++cnt == k){ 9 ans[col] = '\0'; 10 printf("%s\n", ans); 11 return true; 12 } 13 return false; 14 } 15 16 bool vis[2][26]; 17 memset(vis, false, sizeof(vis)); 18 for (int i = 0; i<2; i++) 19 for (int j = 0; j<6; j++) 20 vis[i][G[i][j][col] - 'A'] = 1; 21 for (int i = 0; i<26; i++) 22 if (vis[0][i] && vis[1][i]){ 23 ans[col] = i + 'A'; 24 if (dfs(col + 1)) return true; 25 } 26 27 return false; 28 } 29 int main() 30 { 31 /* 32 freopen("in.txt", "r", stdin); 33 freopen("out.txt", "w", stdout); 34 */ 35 int T; 36 scanf("%d", &T); 37 while (T--){ 38 scanf("%d", &k); 39 for (int i = 0; i<2; i++) 40 for (int j = 0; j<6; j++) 41 scanf("%s", G[i][j]); 42 43 cnt = 0; 44 if (!dfs(0)) puts("NO"); 45 } 46 /* 47 fclose(stdin); 48 fclose(stdout); 49 */ 50 return 0; 51 }