2009-01-15 16:41:42來源不明

2008 NPSC B. 首領的名字

比#前後的字母!

/******************************************************/

  1. #include<stdio.h>      
  2. #include<stdlib.h>   
  3. #include<string.h>   
  4. main()   
  5. {   
  6.  int n,m,a,b,c,d,temp,time,time1,temp1,k;   
  7.  char x[100],y[100];   
  8.   while(scanf("%d ",&n)==1)   
  9.    {        
  10.     for(a=1;a<=n;a++)   
  11.      {   
  12.       gets(x);   
  13.       printf("DATA SET #%d:\n",a);   
  14.       scanf("%d ",&m);   
  15.       for(c=0;c<m;c++)   
  16.        {   
  17.         gets(y);temp=0;time=0;temp1=0;time1=0;   
  18.         k=strlen(y)-1;   
  19.         for(b=0;b<strlen(x);b++)   
  20.          {   
  21.           if(x[b]!='#')            /*比頭*/  
  22.            {   
  23.             if(x[b]==y[b])   
  24.              {temp++;}   
  25.             time++;   
  26.            }   
  27.           if(x[b]=='#')   
  28.            break;    
  29.          }   
  30.         for(b=strlen(x)-1;b>0;b--)   
  31.          {   
  32.           if(x[b]!='#')            /*比尾*/  
  33.            {   
  34.             if(x[b]==y[k])   
  35.              {temp1++;k--;}   
  36.             time1++;   
  37.            }   
  38.           if(x[b]=='#')   
  39.            break;    
  40.          }    
  41.             
  42.         if(time+time1==temp1+temp)   
  43.          printf("POSSIBLE\n");   
  44.         else  
  45.          printf("IMPOSSIBLE\n");     
  46.        }      
  47.      }   
  48.    }     
  49.  return 0;        
  50. }