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

Helpp ! Helpp !

Posted by Enemy94 at 2008-01-18 00:52:56 on Problem 2845
#include <stdio.h>
#include <string.h>

FILE *in=fopen ("input.txt","r");
FILE *out=fopen ("output.txt","w");

int n,c,d,flag;
char a[1000],b[1000],save[1000];

int main (){
	int i,j;
	fscanf (in,"%d",&n);
	for (i=0;i<n;i++){
		flag=0;
		fscanf (in,"%s %s",&a,&b);
		c=strlen(a);
		d=strlen(b);
		if (c>d){
			for (j=0;j<c;j++) save[j]=0;
			d--;
			for (j=c-1;j>=0;j--){
				if (d>=0) save[j]+=a[j]+b[d]-48;
				else save[j]+=a[j];
				if (save[j]>='2' && j!=0) save[j]-=2,save[j-1]=1;
				d--;
			}
		}
		else{
			for (j=0;j<d;j++) save[j]=0;
			c--;
			for (j=d-1;j>=0;j--){
				if (c>=0) save[j]+=a[c]+b[j]-48;
				else save[j]+=b[j];
				if (save[j]>='2' && j!=0) save[j]-=2,save[j-1]=1;
				c--;
			}
		}
		fprintf (out,"%d ",i+1);
		for (j=0;j<strlen(save);j++){
			if (flag==0 && save[j]=='0' && j!=strlen(save)-1) continue;
			flag=1;
			if (save[j]!='2') fprintf (out,"%c",save[j]);
			else fprintf (out,"10");
		}
		fprintf (out,"\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