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:终于ac了。。。心都碎了!!!!改过!!!

Posted by xxnan at 2010-12-13 19:49:41 on Problem 2845 and last updated at 2010-12-13 19:50:03
In Reply To:Re:终于ac了。。。心都碎了!!!! Posted by:xxnan at 2010-12-08 20:25:27
#include<stdio.h>
#define N 82
main()
{
   int n,i,j,l1,l2,k,x,y,flag;
   char s[N],t[N];
   int a[N],b[N],c[N];
   scanf("%d",&n);
   for(i=1;i<=n;i++)
     {
	    scanf("%s%s",s,t);x=0;y=0;flag=1;
	    l1=strlen(s);l2=strlen(t);
	    for(j=0;j<l1;j++)
	    {a[j]=(s[j]-48);
		 if(a[j]==0)x++; 
		}
	    for(j=0;j<l2;j++)
	    {b[j]=(t[j]-48);
	     if(b[j]==0)y++;
	    }
	    if(x==l1&&y==l2)
	    {printf("%d ",i);
	     printf("0\n");}
	    else
	    {
	    if(l1>l2)
	      {
		     for(j=0;j<l1-l2;j++)
		     c[j]=0;
		     for(j=l1-l2;j<l1;j++)
		     c[j]=b[j-l1+l2];
		     for(k=l1-1;k>0;k--)
		       {
			      a[k-1]+=(a[k]+c[k])/2;
			      a[k]=(a[k]+c[k])%2;
			   }
			 a[0]=a[0]+c[0];
			 if(a[0]>=2)
			   {
			     a[0]=a[0]%2;
			     printf("%d ",i);
		         printf("1");
		         for(k=0;k<=l1-1;k++)
		            printf("%d",a[k]);
		            printf("\n");
			   } 
			 else
			   {
                
			     printf("%d ",i);
		         for(k=0;k<=l1-1;k++)
		            {
					  if(a[k]==0&&flag!=0)continue;
					  printf("%d",a[k]);flag=0;}
		            printf("\n");
			   }   
		  }
		  else
		  {
		     for(j=0;j<l2-l1;j++)
		     c[j]=0;
		     for(j=l2-l1;j<l2;j++)
		     c[j]=a[j-l2+l1];
		     for(k=l2-1;k>0;k--)
		       {
			      b[k-1]+=(b[k]+c[k])/2;
			      b[k]=(b[k]+c[k])%2;
			   }
			 b[0]=b[0]+c[0];
			 if(b[0]>=2)
			   {
			     b[0]=b[0]%2;
			     printf("%d ",i);
		         printf("1");
		         for(k=0;k<=l2-1;k++)
		            printf("%d",b[k]);
		            printf("\n");
			   } 
			 else
			   {
                 
			     printf("%d ",i);
		         for(k=0;k<=l2-1;k++)
		            {
			         if(b[k]==0&&flag!=0)continue; 
					printf("%d",b[k]);
					flag=0;}
		            printf("\n");
			   }   
		  }
	 }
     }
	 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