#include<stdio.h> #include<string.h> #include<map> using namespace std; char a[1010]; char b[1010]; //map<char,char>m; char c[2020]; //multimap<char,char>::iterator it; int main() { int _case,n; char x,y; int al,bl,i,j,ij; scanf("%d",&_case); for(ij=1;ij<=_case;ij++) { memset(a,'\0',sizeof(a)); memset(b,'\0',sizeof(b)); //m.clear(); getchar(); scanf("%s",a); //printf("@%d/n",sizeof(a)); al=strlen(a); scanf("%s",b); bl=strlen(b); //printf("%d\n",bl); scanf("%d",&n); for(j=0;j<n;j++) { getchar(); scanf("%c %c",&x,&y); //m[x]=y; c[2*j]=x; c[2*j+1]=y; //m.insert(pair<char,char>(y,x)); } int k=0; for(j=0;j<al&&k<bl;) { if(a[j]==b[k])j++,k++; else { for(i=0;i<n;i++) if(b[k]==c[i*2]&&a[j]==c[i*2+1]) { j++; k++; break; } if(i==n)k++; //printf("%d %d\t",j,k); } } printf("Case #%d: ",ij); if(j==al)printf("happy\n"); else printf("unhappy\n"); } return 0; }
map还得金山赛抱鸭蛋!!~~