200 - Don't know why Wrong Answer....

All about problems in Volume II. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

200 - Don't know why Wrong Answer....

Postby b821213 » Sun Feb 05, 2012 2:20 pm

Code: Select all
#include <cstdio>
#include <cstring>

bool m[26][26];
int ind[26];
bool used[26];

void cmp(char a[],char b[]){
   for(int i=0;a[i]&&b[i];++i)
      if( a[i] != b[i] ){
         int t1 = a[i]-'A';
         int t2 = b[i]-'A';
         m[t1][t2] = 1;
         used[t1] = used[t2] = 1;
         ++ind[t2];
         return;
      }
}

int main(){
   
   char last[100];
   char now[100];
   bool only = 1;
   
   scanf("%s",last);
   
   while(1){   
      scanf("%s",now);      
      if( now[0] == '#' ) break;

      only = 0;
      cmp(last,now);
      strcpy(last,now);
   }
   
   int q[26];
   int qf = 0 , qn = 0;
   
   for(int i=0;i<26;++i)
      if( used[i] && ind[i]==0 )
         q[qn++] = i;
   
   while( qf < qn ){
      int f = q[qf++];
      printf("%c",'A'+f);
      for(int i=0;i<26;++i)
         if( m[f][i] ){
            --ind[i];
            if( ind[i] <= 0 ) q[qn++] = i;
         }
   }
   
   if( only ) printf("%c",last[0]);
   
   printf("\n");

   return 0;
}


my code is very short , but i can't find any bug in my code.....

is there anyone can help me?
b821213
New poster
 
Posts: 6
Joined: Sun Apr 24, 2011 3:01 pm
Location: Taiwan

Re: 200 - Don't know why Wrong Answer....

Postby Mira13 » Sat Mar 03, 2012 3:05 am

b821213 wrote:
Code: Select all
#include <cstdio>
void cmp(char a[],char b[]){
   for(int i=0;a[i]&&b[i];++i)
      if( a[i] != b[i] ){
         int t1 = a[i]-'A';
         int t2 = b[i]-'A';
         m[t1][t2] = 1;
         used[t1] = used[t2] = 1;
         ++ind[t2];
         return;
      }
}




at the first glance, ur cmp function is not correct.
it doesn't take in account previous letters in the words, only current.
Mira13
New poster
 
Posts: 1
Joined: Sat Mar 03, 2012 2:55 am


Return to Volume II

Who is online

Users browsing this forum: No registered users and 0 guests