题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4545
这个题目没什么好解释的,在一个串中找另外一个串就行了,没什么难度
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <map>
using namespace std;
#define maxn 1500
char first[maxn],second[maxn],str[10];
int n,m;
map<char,set<char> > e;
bool find_ans(){//first变成second只要在first里面找到second就行了
int i=0,j=0,k;
while(second[i]){
k=1;
for(j;first[j];j++)
if(first[j]==second[i] || e[first[j]].find(second[i])!=e[first[j]].end()){
j++; k=0; break;
}
i++;
if(k) return false;
}
return true;
}
int main(){
int i,j,k=0,t;
scanf("%d",&t);
while(t--){
scanf("%s%s",second,first);
e.clear();
scanf("%d",&m);
for(i=0;i<m;i++){
scanf("%s%s",str,str+5);
e[str[0]].insert((str+5)[0]);
}
printf("Case #%d: ",++k);
if(find_ans()) printf("happy\n");
else printf("unhappy\n");
}
return 0;
}