您的位置:首页 > 其它

UVa1262 - Password

2015-10-08 21:49 141 查看
不知道哪错了。。0.0

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <string>
using namespace std;
const int INF = ~0U >> 1;
const int maxn = 7;
char s1[maxn][maxn], s2[maxn][maxn];
string str[maxn];
int T, k, cnt = 0;

void init() {
memset(s1, 0, sizeof(s1));
memset(s2, 0, sizeof(s2));
for(int i = 0; i < maxn; ++i) str[i].clear();
return ;
}

int dfs(int n, char* ans) {
if(n == 5) {
++cnt;
if(cnt == k) {
printf("%s\n", ans);
return 1;
}
return 0;
}
for(int i = 0; i < str
.size(); ++i) {
ans
= str
[i];
if(dfs(n + 1, ans)) return 1;
ans
= 0;
}
}

int main() {
scanf("%d", &T);
while(T--) {
cnt = 0;
init();
scanf("%d", &k);
for(int i = 0; i < 6; ++i)
scanf("%s", s1[i]);
for(int i = 0; i < 6; ++i)
scanf("%s", s2[i]);

for(int i = 0; i < 5; ++i) {
int cnt = 0;
for(int j = 0; j < 6; ++j)
for(int k = 0; k < 6; ++k)
if(s1[j][i] == s2[k][i]) str[i].push_back(s1[j][i]);
}
//        for(int i = 0; i < 5; ++i) cout << str[i] << endl;
bool ok = true;
for(int i = 0; i < 5; ++i) {
unique(str[i].begin(), str[i].end());
sort(str[i].begin(), str[i].end());
if(str[i].size() == 0) ok = false;
}
if(!ok) {
printf("NO\n");
continue;
}
char s[maxn] = {0};
if(!dfs(0, s)) printf("NO\n");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: