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

帮我看看我的程序,老是wrong answer,我确定没有错误啊,是不是格式有要求啊?

Posted by chavez1986 at 2009-08-04 11:22:23 on Problem 1001
/*
 * main.c
 *
 *  Created on: 2009-8-1
 *      Author: chavez
 */
#include <stdio.h>

#define MAX_LENGHT	5*25
char szLine[6];
int n;
int main() {
	while(scanf("%s%d",szLine,&n)!=EOF){
		if(n == 0){
			printf("1\n");
			continue;
		}


		//szLine[6] = { '0' };//in
		int result[MAX_LENGHT] = { 0 };//out
		int a[5] = { 0 };//被乘数
		int b[MAX_LENGHT] = { 1, 0 };//乘数

		int i, dflag = 0;
		int dot = 0;//the position of dot
		int j = 0;
		int k, m;
		int length = 0;
		int start = 0;
		int resultDotPosition;

		//judge 小数点后面有没有0

		for (i = 0; i < 5; i++) {
			if (szLine[i] == '.' && i != 5)
				dflag = 1;
		}
		//deal with in

		for (i = 0; i <= 5; i++) {
			if (dflag) {
				if (szLine[5 - i] == '0') {
					if (szLine[4 - i] != '0')
						dflag = 0;
					dot--;
					continue;
				}
			}

			if (szLine[5 - i] != '.') {
				a[j] = szLine[5 - i] - '0';
				j++;
			} else {
				dot += i;
			}

		}

		for (k = 0; k < n; k++) {
			for (i = 0; i < 5; i++) {
				for (j = 0; j < MAX_LENGHT; j++) {
					result[i + j] += a[i] * b[j];
				}
			}

			for (i = 0; i < MAX_LENGHT; i++) {
				if (result[i] >= 10) {
					result[i + 1] += result[i] / 10;
					result[i] %= 10;
				}
			}
			if (k == n - 1)
				break;
			for (i = 0; i < MAX_LENGHT; i++) {
				b[i] = result[i];
				result[i] = 0;
			}

		}

		for (i = MAX_LENGHT - 1; i >= 0; i--) {
			if (result[i]) {
				length = i + 1;
				break;
			}
		}
		resultDotPosition = dot * n;
		m = length - dot * n;
		if (m < 0) {
			printf(".");
			for (j = -m; j > 0; j--) {
				printf("0");
			}

		}
		for (i = MAX_LENGHT - 1; i >= 0; i--) {
			if (i == resultDotPosition - 1 && m >= 0)
				printf(".");
			if (start == 1)
				printf("%d", result[i]);
			else if (result[i]) {
				printf("%d", result[i]);
				start = 1;
			}

		}
		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