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 chan at 2014-01-02 20:34:08 on Problem 1503
In Reply To:唉……我真的挂在大树上了,求破解!各种情况都考虑了…… Posted by:1200017623 at 2013-01-07 22:06:54
> //下面是我的源代码 WA了……
> 
> #include<iostream>
> #include<string>
> using namespace std;
> int a0[41] = {0};         //我准备用整数数组存储,1个存5位,这样一共有205位,绝对够了……
> void add(int*sum1,int*sum2){        //add up
> 	int add = 0;
>         //这句貌似没有必要,但有备无患吧
> 	memset(a0,0,41*sizeof(int));
> 	for(int i = 40;i >= 0;--i){
> 		if(sum1[i] == 0 && sum2[i] == 0 && add == 0)break;
> 		a0[i] = sum1[i] + sum2[i] + add;
> 		add = a0[i]/100000;
> 		a0[i] %= 100000;
> 	}
> }
> int expo(int n){        //calculate value: 10^n
> 	int i = 1;
> 	for(int j = 0;j < n;++j)i*=10;
> 	return i;
> }
> int input(int*num){  //输入字符串,转成整型数组存储,若输入为0则返回0
> 	char temp[200] = {0},temp2[200] = {0};
> 	cin>>temp2;
> 	int n;
> 
> 	/* Omit leading zeros*/
> 	for(n = 0;n < 200 && temp2[n] == '0';++n);
> 	if(temp2[n] == '\0')return 0;
> 	for(int i = 0;temp2[n] != '\0';++i,++n)temp[i] = temp2[n];
> 
> 	/* Reverse the string*/
> 	int len = strlen(temp);
> 	char *p = temp,*q = temp + len - 1,t;
> 	for(;p < q;++p,--q){
> 		 t = *p,*p = *q,*q = t;
> 	}
> 	
> 	/* Transfer char into int array*/
> 	memset(num,0,41*sizeof(int));
> 	n = 0;
> 	for(int i = 40;temp[n];--i){
> 		for(int j = 0;temp[n] && j < 5;++n,++j){
> 			num[i] += (temp[n] - 48) * expo(n%5);
> 		}
> 	}
> 	return 1;
> }
> void output(){
> 	int i;
>         //找到第一个不是零的整数,原样输出。
>         //后面的整数要连前面的0一起输出,凑够5位
> 	for(i = 0;i < 41 && a0[i] == 0;++i);
> 	printf("%d",a0[i]);
> 	for(i = i+1;i < 41;++i)printf("%05d",a0[i]);
> 	printf("\n");
> }
> int main(){
>         //sum2循环使用读入新数据,加的结果存进全局数组a0里面
>         //sum1用于记录当前的和,再与sum2相加
> 	int sum1[41] = {0},sum2[41] = {0};
> 	input(sum1);
> 	if(sum1[40] == 0){     //连没有输入的情况都考虑了!真无语……
> 		printf("0\n");
> 		return 0;
> 	}
> 	for(int i = 0;i < 41;++i)a0[i] = sum1[i];
> 	while(input(sum2)){
> 		add(sum1,sum2);
> 		for(int i = 0;i < 41;++i)sum1[i] = a0[i];
> 	}
> 	output();
> 	cin.get();
> 	cin.get();
> 	return 0;
> }
> /*
> 这是一些自造的测试数据,VC++2010环境下全部都能通过
> 
> 174800265
> 139587
> 000100
> 2415161
> 001
> 0999999999
> 0
> 1177355113
> 
> 999
> 99999
> 0
> 100998
> 
> 
> 002
> 999999999999999
> 0
> 1000000000000001
> */

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