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

哪位高手帮忙看下,数据都通过了,就是WA

Posted by LXpeng at 2008-12-14 11:22:39 on Problem 2845
#include <iostream>
#include <cstring>
using namespace std;

void swap1(char a[]);
int main() {
	int N;
	char sums[82];
	while(scanf ("%d",&N)!=EOF)
	{
		for(int ii=1;ii<=N;ii++)
		{
			char first[81],second[81];
			char len;
			char sum[82];
			memset(sum, 0, sizeof(sum));
			sum[0]='0';
			scanf("%s %s",&first,&second);
			if(strlen(first)>strlen(second))
				len=strlen(first);
			else 
				len=strlen(second);
			swap1(first);
			swap1(second);
			for(char i=0;i<len;i++)
			{
				if(first[i]!='0'&&first[i]!='1')
					first[i]='0';
				if(second[i]!='0'&&second[i]!='1')
					second[i]='0';
				if(sum[i]!='1')
					sum[i]='0';			
				sum[i]+=first[i]+second[i]-'0'-'0';
				if(sum[i]>='2')
				{
					sum[i]-=2;
					sum[i+1]='1';
				}
				if(i==len-1)
					if(sum[i+1]=='1')
						sum[i+2]='\0';
					else
						sum[i+1]='\0';
			}
			swap1(sum);
			int k=0,l=strlen(sum);
			for(int j=0;j<strlen(sum);j++)
			{
				if(sum[j]=='1'){l=j;break;}
			}
			for(int dd=l;dd<strlen(sum);dd++)
			{
				sums[k]=sum[dd];
				k++;
			}
			sums[k]='\0';
			if(sums[0]=='\0')
				printf("%d 0\n",ii);
			else
				printf("%d %s\n",ii,sums);
		}
	}
	return 0;
}

void swap1(char a[])
{
	char len,temp;
	len=strlen(a);
	for(char i=0;i<len;i++)
	{
		if(i==len-i-1||i==len-i)
			break;
		temp=a[i];
		a[i]=a[len-i-1];
		a[len-i-1]=temp;
	}
}


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