hdu1063

/**/
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <stack>
#include <queue>

typedef long long LL;
using namespace std;

char s[15];
int num;
int a[305], ans[305], c[305];
int cnt;

void Plus(){
	memset(c, 0, sizeof(c));
	for (int i = 0; i < cnt; i++){
		for (int j = 0; j < 300; j++){
			c[i + j] += a[i] * ans[j];
		}
	}
	for (int i = 0; i < 300; i++){
		if(c[i] >= 10){
			c[i + 1] += c[i] / 10;
			c[i] %= 10;
		}
	}
	memcpy(ans, c, sizeof(c));
}

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);

	while(scanf("%s %d", s, &num) == 2){
		int len = strlen(s);
		int xlen = 0;
		memset(ans, 0, sizeof(ans));
		memset(a, 0, sizeof(a));
		int ju = 0;
		for (int i = len - 1; i >= 0; i--){
			if(s[i] == '0') continue;
			else if(s[i] == '.' && s[i + 1] == '0'){
				ju = 1;
				break;
			}else break;
		}
		for (int i = len - 1; i >= 0; i--){
			if(s[i] == '.'){
				xlen = len - 1 - i;
				break;
			}
		}
		cnt = 0;
		for (int i = len - 1; i >= 0; i--){
			if(s[i] >= '0' && s[i] <= '9'){
				a[cnt] = s[i] - '0';
				ans[cnt] = a[cnt];
				cnt++;
			}
		}
		for (int i = 2; i <= num; i++){
			Plus();
		}
		int i;
		for (i = 300; i >= xlen * num; i--){
			if(ans[i]) break;
		}
		for (; i >= xlen * num; i--){
			printf("%d", ans[i]);
		}
		if(xlen > 0 && !ju) printf(".");
		for (; i >= 0; i--){
			int flag = 0;
			for (int j = i; j >= 0; j--){
				if(ans[j]){
					flag = 1;
					break;
				}
			}
			if(flag) printf("%d", ans[i]);
		}
		printf("\n");
	}

	return 0;
}
/**/

写的有点丑

全部评论

相关推荐

点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
11-26 16:06
已编辑
快手电商 后端 23k-35k
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务