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

为什么我的代码AC不了,楼上给的测试数据都过了!!!求大神解救。

Posted by yd_liu at 2014-11-12 12:47:46 on Problem 1001
#include <stdio.h>
//#include <stdlib.h>
#include <string.h>

void add(char a[], char b[], int len1, int len2){
	int index;
	for(index = len1; index >= len2; index--){
		if (a[index]+b[index]-'0'-'0' >= 10){
			a[index] = a[index]+b[index]-'0'-10;
			a[index-1] += 1;
		}
		else a[index] = a[index]+b[index]-'0';
	}
}

int main(){
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);

	char result_temp1[131], result_temp2[131], result[131];
	char base[7];
	char r[7];
	int i, j, k, n, real_num, decimal_num, temp, mul_temp; //num = the number of

	memset(r,'\0',sizeof(r));

	while(scanf("%s%d",r,&n) != EOF){
		memset(result, '0', sizeof(result));
		memset(base,'\0',sizeof(base));
		//input
		real_num = 0;
		decimal_num = 0;
		for(i = 0; i < strlen(r); i++)
			if (r[i] == '.') break;
		for(j = 0; j < i; j++)
			if (r[j] == '0') continue;
			else break;
		for(k = j; k < i; k++)
			base[real_num++] = r[k];
		for(j = strlen(r)-1; j > i; j--)
			if (r[j] == '0') continue;
			else break;
		for(k = i+1; k <= j; k++){
			base[real_num++] = r[k];
			decimal_num++;
		}
		for(i = 0; i < strlen(base); i++)
			if (base[i] == '0') continue;
			else break;
		if (i){
			real_num = 0;
			for(j = i; j < strlen(base); j++)
				base[real_num++] = base[j];
			for(k = real_num; k < strlen(base); k++)
				base[k] = '\0';
		}
		memcpy(&result[130-real_num], base, real_num);
        //process
		for(k = 0; k < n-1; k++){
			memset(result_temp2, '0', sizeof(result_temp2));
			for(i = strlen(base)-1; i >= 0; i--){
				memset(result_temp1, '0', sizeof(result_temp1));
				mul_temp = 0;
				for(j = 0; j < real_num; j++){
					temp = (base[i]-'0')*(result[130-1-j]-'0');
					temp += mul_temp;
					result_temp1[130-1-j-(strlen(base)-1-i)] += temp%10;
					mul_temp = temp/10;
				}
				result_temp1[130-1-real_num-(strlen(base)-1-i)] += mul_temp;
				add(result_temp2, result_temp1, 130-1, 130-1-real_num-(strlen(base)-1-i));
			}
			memcpy(result,result_temp2,sizeof(result));
			if (mul_temp == 0) real_num += (strlen(base)-1);
			else real_num += strlen(base);
		}
		//output
		memset(result_temp1, '\0', sizeof(result_temp1));
		if (decimal_num*n == 0) memcpy(result_temp1, &result[130-real_num], real_num);
		else if (decimal_num*n < real_num){
			memcpy(result_temp1, &result[130-real_num], real_num-decimal_num*n);
			result_temp1[real_num-decimal_num*n] = '.';
			memcpy(&result_temp1[real_num-decimal_num*n+1], &result[130-decimal_num*n], decimal_num*n);
		}
		else{
			result_temp1[0] = '.';
			memset(&result_temp1[1], '0', decimal_num*n-real_num);
			memcpy(&result_temp1[decimal_num*n-real_num+1], &result[130-real_num], real_num);
		}

		puts(result_temp1);
		memset(r,'\0',sizeof(r));
	}

	//system("pause");
	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