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

为什么我一直RE啊

Posted by Cunch at 2010-04-07 12:51:18 on Problem 2845
#include<stdio.h>
#include<string.h>

char str1[1000],str2[1000],str[1000],mid[1000];
int main()
{
     int i,j,k,t,len1,len2,len,max;
     char carry[2];

     scanf("%d\n",&t);
     k=0;
     while(t--)
     {
          k++;
          //scanf("%s",str1);
          //scanf("%s",str2);
          gets(str);
          i=0;
          while(str[i]!=' ')
          {
               str1[i] = str[i];
               i++;
          }
          str1[i]='\0';
          strcpy(str2,&str[i+1]);

          len1 = strlen(str1);
          len2 = strlen(str2);
         // printf("%d %d\n",len1,len2);

          carry[0]='0'; carry[1]='\0';
          if(len1>len2)
          {
               strcat(carry,str1);
               strcpy(str1,carry);
               for(i=0;i<=len1-len2;i++) mid[i]='0';
                    mid[i]='\0';
               strcat(mid,str2);
               strcpy(str2,mid);
          }
          else if(len2>len1)
          {
               strcat(carry,str2);
               strcpy(str2,carry);
               for(i=0;i<=len2-len1;i++) mid[i]='0';
                    mid[i]='\0';
               strcat(mid,str1);
               strcpy(str1,mid);
          }
          else
          {
               strcat(carry,str1);
               strcpy(str1,carry);
               carry[0]='0'; carry[1]='\0';
               strcat(carry,str2);
               strcpy(str2,carry);
          }
          //printf("%s %s\n",str1,str2);
          //  printf("%s %s\n",str1,str2);

          carry[0]='0';
          max = (len1>len2)?len1:len2;
          for(i=max;i>=0;i--)
          {

               if(str1[i]=='0'&&str2[i]=='0')
               {
                    if(carry[0]=='0') str[i]='0';
                    else if(carry[0]=='1') {str[i]='1'; carry[0]='0';}
               }
               else if(str1[i]=='0'&&str2[i]=='1')
               {
                    if(carry[0]=='0') str[i]='1';
                    else if(carry[0]=='1') { str[i]='0'; carry[0]='1';}
               }
               else if(str1[i]=='1'&&str2[i]=='0')
               {
                    if(carry[0]=='0') str[i]='1';
                    else if(carry[0]=='1') { str[i]='0'; carry[0]='1';}
               }
               else if(str1[i]=='1'&&str2[i]=='1')
               {
                   if(carry[0]=='0') { str[i]='0'; carry[0]='1';}
                   else if(carry[0]=='1') { str[i]='1'; carry[0]='1';}
               }
          }
          str[max+1]='\0';

          i=0;
          while(str[i]=='0') i++;
          if(str[i]=='\0') i = i-1;
          printf("%d %s\n",k,&str[i]);
     }
     return 0;
}

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