首页 新闻 会员 周边 捐助

UVa OJ 465 - Overflow WA 求助!!!!

0
悬赏园豆:50 [已关闭问题] 关闭于 2012-11-11 18:26
#include<stdio.h>
#include<string.h>
int is_plus(int jlen, int ilen, int sum[], char inter[], char jnter[])
{
    int i, j, t, loop, temp, e = 0 ;
    for(j=jlen-1; j>=0; --j)
        {
            loop = jlen-1-j;
            for(i=ilen-1; i>=0; --i, ++loop)
            {
                temp = sum[loop];
                sum[loop] = (e+sum[loop]+(inter[i]-'0')*(jnter[j]-'0'))%10;
                e = (e+temp+(inter[i]-'0')*(jnter[j]-'0'))/10;
            }
            for(t=loop; t<1004 && e; ++t)
            {
            temp = sum[t];
            sum[t] = (e + sum[t])%10;
            e = (e + temp)/10;
            } 
        }
 return 0;
}

int is_add(int jlen, int ilen, int sum[], char inter[], char jnter[])
{
    int len, j, i, e = 0, temp;
    len = ilen < jlen ? ilen:jlen;
    for(i=0; i<len; ++i)
        {
            temp = sum[i];
            sum[i] = (e + sum[i] + (inter[len-i-1]-'0') + (jnter[jlen-i-1]-'0'))%10;
            e = (e + temp + (inter[len-i-1]-'0') + (jnter[jlen-i-1]-'0'))/10;
        }
   if(ilen-len>0) 
   for(j=i; j<ilen; ++j) 
     {
            temp = sum[j];
            sum[j] = (e + sum[j] + (inter[j]-'0'))%10;
            e = (e + temp +(inter[j]-'0'))/10;
        }   
        
   else if(jlen-len>0)
  for(j=i; j<jlen; ++j) 
     {
            temp = sum[j];
            sum[j] = (e + sum[j] + (jnter[j]-'0'))%10;
            e = (e + temp +(jnter[j]-'0'))/10;
        } 
        for(j=i; j<1004 && e; ++j)
        {
            temp = sum[j];
            sum[j] = (e + sum[j])%10;
            e = (e + temp)/10;
        }
  return 0;
}



int main()
{

   int i, j, ilen, jlen, sum[1004], fflag, t, temp;
   char cali[502], calj[502], calij[502], flag, *judge="7463847412";
   memset(sum, 0, sizeof(sum));
   memset(cali, 0, sizeof(cali));
   memset(calj, 0, sizeof(calj));
   memset(calij, 0, sizeof(calij));
   while(scanf("%s", calij) != EOF)
   {
         getchar();
         fflag = temp = 0;
         printf("%s", calij);
         ilen = strlen(calij);
         for(i=0; (calij[i]-'0' == 0)&&i<ilen-1; ++i);
         t = ilen;
         ilen = ilen - i;
         for(j=0; j<502&&i<t; ++i, ++j)
         {
           cali[j] = calij[i];     
      }
      memset(calij, 0, sizeof(calij));
         flag = getchar();
         getchar();
         printf(" %c ", flag);
         scanf("%s", calij);
         getchar();
         printf("%s\n", calij);
         jlen = strlen(calij);
         for(i=0; (calij[i]-'0' == 0)&&i<jlen-1; ++i);
         t = jlen;
         jlen = jlen - i;
         for(j=0; j<502&&i<t; ++i, ++j)
         {
           calj[j] = calij[i];     
      }
         if(ilen > 10){temp=1; printf("first number too big\n");}
         
         else if(ilen == 10)
         {
                 i = 0;
                 while(cali[i]-'0' == judge[9-i]-'0' && i<10) ++i;
            if(cali[i]-'0'>(judge[9-i]-'0')) printf("first number too big\n");
          
      }
      
         if(jlen > 10){temp=1; printf("second number too big\n");}
         else if(jlen == 10)
         {
          i = 0;
                 while(calj[i]-'0' == judge[9-i]-'0' && i<10) ++i;
            if(calj[i]-'0'>(judge[9-i]-'0')) printf("second number too big\n");    
      }
         
         
         
         switch(flag)
         {
           case '*':     is_plus(jlen, ilen, sum, cali, calj); break;
           case '+':  is_add(jlen, ilen, sum, cali, calj); break;
           default: return 1;
      }
      {
          for(i=1003; !sum[i]&& i>=9; --i);
          if(i>=10) printf("result too big\n");
          else if(i == 9)
        {
            while(sum[i] == judge[i]-'0' && i>0) --i;
            if(sum[i]>(judge[i]-'0')) printf("result too big\n");
          } 

      }
      memset(sum, 0, sizeof(sum));
      memset(cali, 0, sizeof(cali));
      memset(calj, 0, sizeof(calj));
      memset(calij, 0, sizeof(calij));
   }
   return 0;    
}

WA了差不多十次了,虽然说百度之后能看到有比我这短了几倍的代码,但我调试了两天,WA 了那么多次的确有点不甘心,所以,希望哪位做过此题的前人能够帮我测试一下代码,不为了别的,只是希望能够帮帮我不要再把时间放在这里了……

Gifur的主页 Gifur | 初学一级 | 园豆:73
提问于:2012-11-09 17:03
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册