hdu 1113 Word Amalgamation

来源:互联网 发布:vmware12安装linux 编辑:程序博客网 时间:2024/05/21 11:01

题意:第一个XXXXXX前面的是字典,之后的是查询的关键词语,目标是找到字典中与其相同字母构成的字符串。

题解:不得不说,大神就是大神。。。。

#include <iostream>#include <string>#include <map>#include <algorithm>using namespace std;map<string, string> str;string s, t;int main(){while(cin >> s && s != "XXXXXX"){t = s;sort(s.begin(), s.end());str[t] = s;}while(cin >> s && s != "XXXXXX"){bool flag = 0;t = s;sort(s.begin(), s.end());for(map<string, string>::iterator it=str.begin(); it!=str.end(); ++it)if(it->second == s){cout << it->first << endl;flag = 1;}if(flag == 0)cout << "NOT A VALID WORD\n";cout << "******\n";}return 0;}
这是我的苦逼代码。。。。。。利用了优先队列

#include<cstdio>#include<cstring>#include<cmath>#include<ctime>#include<algorithm>#include <iostream>#include <queue>#include <stack>#include <vector>#include <map>#include <set>#define INF 0x3f3f3f3f#define maxn 1000100#define mem(a) memset(a,0,sizeof(a))using namespace std;typedef long long ll;int main(){    priority_queue <string,vector<string>,greater<string> > q;    char c,s[100],s1[110][10],s2[110][10];    int num1[110][33] = {0},num2[110][33] = {0},k1 = 0,k2 = 0;    while(scanf("%s",s1[k1++]))    {        if(s1[k1-1][0] == 'X')            break;        for(int i = 0; i < strlen(s1[k1-1]); i++)            num1[k1-1][s1[k1-1][i]-'a']++;    }    while(scanf("%s",s2[k2++]))    {        if(s2[k2-1][0] == 'X')            break;        for(int i = 0; i < strlen(s2[k2-1]); i++)            num2[k2-1][s2[k2-1][i]-'a']++;    }    for(int i = 0; i < k2-1; i++)    {        for(int j = 0; j < k1-1; j++)        {            int k;            for(k = 0; k < 26; k++)                if(num1[j][k] != num2[i][k])                    break;            if(k == 26)                q.push(s1[j]);        }        if(q.empty())            printf("NOT A VALID WORD\n");        else            while(!q.empty())        {            string s = q.top();            cout <<s<<endl;            q.pop();        }        printf("******\n");    }return 0;}



0 0