UVA 1262(p323p)----Password

来源:互联网 发布:完美汽配软件 编辑:程序博客网 时间:2024/06/07 17:45
#include<iostream>#include<cstdio>#include<vector>#include<algorithm>using namespace std;int t,k;char tmp[10];char st1[10][10],st2[10][10];vector<string> ans;vector<char> st[10];void prepare(){    for(int j=0; j<5; j++)    {        for(int i=0; i<6; i++)            for(int k=0; k<6; k++)                if(st1[i][j]==st2[k][j])                {                    st[j].push_back(st1[i][j]);                    break;                }    }}void solve(int dep){    if(dep==5)    {        string st="";        for(int i=0; i<5; i++)            st+=tmp[i];        ans.push_back(st);        return ;    }    for(int i=0; i<st[dep].size(); i++)    {        tmp[dep]=st[dep][i];        solve(dep+1);    }}void init(){    ans.clear();    for(int i=0; i<5; i++) st[i].clear();}int main(){    scanf("%d",&t);    while(t--)    {        init();        cin>>k;        for(int i=0; i<6; i++)            scanf("%s",st1[i]);        for(int i=0; i<6; i++)            scanf("%s",st2[i]);        prepare();        solve(0);        sort(ans.begin(),ans.end());        int num=unique(ans.begin(),ans.end())-ans.begin();        if(num<k) printf("NO\n");        else cout<<ans[k-1]<<endl;    }    return 0;}

0 0
原创粉丝点击