标签:des style blog http color os io java strong
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 1607 Accepted Submission(s): 594
1 #include<stdio.h> 2 #include<string.h> 3 #include<string.h> 4 char xm[1002],xx[1002]; 5 struct chage{ 6 char aa,bb; 7 }; 8 chage mm[102]; 9 int mat[1002][1002]; 10 int max(int a,int b){ 11 return a>b?a:b; 12 } 13 int main() 14 { 15 int tes,n,i,j,k,cas=1; 16 // freopen("test.in","r",stdin); 17 scanf("%d",&tes); 18 while(tes--){ 19 scanf("%s%s",xm,xx); 20 getchar(); 21 scanf("%d",&n); 22 getchar(); 23 for(i=0;i<n;i++){ 24 scanf("%c %c",&mm[i].aa,&mm[i].bb); 25 getchar(); 26 } 27 int lenxm=strlen(xm); 28 int lenxx=strlen(xx); 29 for(i=0;i<lenxm;i++)mat[i][0]=0; 30 for(j=0;j<lenxx;j++)mat[0][j]=0; 31 for(i=0;i<lenxm;i++){ 32 for(j=0;j<lenxx;j++){ 33 if(xm[i]==xx[j]) 34 mat[i+1][j+1]=mat[i][j]+1; 35 else{ 36 for(k=0;k<n;k++){ 37 if(mm[k].aa==xx[j]&&xm[i]==mm[k].bb){ 38 mat[i+1][j+1]=mat[i][j]+1; 39 break; 40 } 41 } 42 if(k==n) mat[i+1][j+1]=max(mat[i+1][j],mat[i][j+1]); 43 } 44 } 45 } 46 if(mat[lenxm][lenxx]==lenxm) 47 printf("Case #%d: happy\n",cas++); 48 else 49 printf("Case #%d: unhappy\n",cas++); 50 } 51 52 return 0; 53 }
标签:des style blog http color os io java strong
原文地址:http://www.cnblogs.com/gongxijun/p/3954474.html