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

C code

Posted by ayxg at 2011-12-07 14:26:15 on Problem 1001
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAX 1024
char buf[MAX];
int main()
{
	char numstr[10]; int i, num, n, s, c; 
	int dotpos = 0, nLen = 0; char *p = numstr;
	while ( scanf("%s%d", numstr, &n) == 2) {
		if (n < 0 || n > 25) return -1;
		if (n == 0) {
			printf("1.0\n");
			continue;
		}
		nLen = strlen(numstr);
		i = 0; while (numstr[i] != '.') ++i;
		dotpos = nLen - i - 1;
		for (; i < nLen; ++i ) numstr[i] = numstr[i+1];
		num = atoi(numstr); memset(buf, 0, MAX * sizeof(buf[0]));
		buf[1] = 1;  dotpos = dotpos * n;
		while (n > 0) {
			s = 0; c = 0;
			for (i = 1; i < MAX; ++i) {
				s = num * buf[i] + c;
				c = s / 10; buf[i] = s % 10;
			}
			--n;
		}
		for (i = MAX-1; buf[i] == 0; --i) ;
		i = (i < dotpos)? dotpos : i;
		while (i>0) {
			if (i == dotpos) printf(".");
			printf("%d", buf[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