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

这样写好点,你写太长了

Posted by lzy_Dennis at 2023-09-13 21:37:10 on Problem 1001
In Reply To:求大神帮我看看啊 WA n次了 不知道错在哪= = Posted by:a4423329 at 2015-11-24 21:43:50
#include <stdio.h>
#include <string.h>
const int N = 200;
int main() {
	char num[6];
	long number;
	int n,point,count;
	int a[N];
	while (scanf("%s%d", num, &n) == 2) {
		number = 0;
		point = -1;
		count = 0;
		int note1,note2;
		for (int i = 0; i <= 5; i++) {
			if (num[i] != '0') {
				note1 = i;
				break;
			}
		}
		for (int i = 5; i >= 0; i--) {
			if (num[i] != '0') {
				note2 = i;
				break;
			}
		}
		for (int i = note1; i <= note2; i++) {
			if (num[i] != '.') {
				number = number*10 + (num[i]-48);
			}
		}
		for (int i = note2; i >= note1; i--) {
			if (num[i] != '.') {
				a[count++] = num[i]-48;
			}
		}
		for (int i = note1; i <= note2; i++) {
			if (num[i] == '.') {
				point = (note2-i)*n;
				break;
			}
		}
		long s,d;
		for (int k = 1; k < n; k++) {
			d = 0;
			for (int i = 0; i < count; i++) {
				s = a[i]*number+d;
				a[i] = s%10;
				d = s/10;
			}
			while (d != 0) {
				a[count++] = d % 10;
				d /= 10;
			}
		}
		bool flag = true;
		if (count < point) {
			flag = false;
			printf(".");
			while (point != count) {
				point--;
				printf("0");
			}
		}
		for (int i = count-1; i >= 0; i--) {
			if (flag == true && i == point-1) printf(".");
			printf("%d", a[i]);
		}
		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