Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

HELp me - WA - 1580

Posted by heru at 2007-11-20 14:54:08 on Problem 1580
Why my code WA?
I think my input and output is right

#include<cstdio>
#include<algorithm>
#include<string.h>

using namespace std;

int main()
{
    char input[1000];
    char *kt1;
    char *kt2;
    int jum[1000];
    int jml,tot,cek;
    while(gets(input))
    {
      jml=0;
      memset(jum,0,sizeof(jum));
      if(strcmp(input,"-1")==0)
      {
        break;
      }
      kt1=strtok(input," ");
      kt2=strtok(NULL," ");
      printf("appx(%s,%s) = ",kt1,kt2); 
      int c=0;
      for(int i=0;i<strlen(kt1);i++)
      {
        for(int j=0;j<strlen(kt2);j++)
        {
          if(kt1[i]==kt2[j])
          {
            jum[c]++;
            int a=i+1;
            int b=j+1;
            while(a < strlen(kt1) && b < strlen(kt2))
            {
                if(kt1[a]==kt2[b])
                {
                  jum[c]++;
                }
                a++;
                b++;
            }
            c++;
          }
        }       
      }
      sort(jum,jum+c);
      jml=jum[c-1];
      jml=jml*2;
      tot=strlen(kt1)+strlen(kt2);
      for(int k=1;k<tot;k++)
      {
        if(jml > 0)
        {
         if(jml % k == 0 && tot % k == 0)
         {
           jml=jml/k;
           tot=tot/k;
         }
        }
      }
      //printf("%d %d\n",jml,tot);
      if(jml == 0)
      {
        printf("0\n",kt1,kt2);
      }
      else if(jml==tot)
      {
           printf("1\n",kt1,kt2);
      }
      else
      {
          printf("%d/%d\n",jml,tot);
      }
    }
    return 0;
}


Please help with English...

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator