⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 1001.cpp

📁 pku acm 1001,share it and enjoy it acm.pku.edu.cn if you have any problems,connect me.
💻 CPP
字号:
// 1001.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include<iostream.h>
#include<string.h>
#include<stdlib.h>
int*  mult(int *s,int a,int *l,int b)
{    int i,j,k=0,t=1;
		int **p;
	p=new int*[a];
	for(i=0;i<a;i++){
		p[i]=new int[a+b];}
	for(i=0;i<a+b;i++){
		for(j=0;j<a;j++){
			p[j][i]=0;}}
	for(i=a-1;i>=0;i--){
		for(j=b-1;j>=0;j--){
			p[k][a+b-t]=s[i]*l[j];t++;}k++;t=k+1;}
	
	int *c;c=new int[a+b];for(i=0;i<a+b;i++){c[i]=0;}
	for(i=0;i<a+b;i++){
		for(j=0;j<a;j++){
			c[i]+=p[j][i];}}delete[]p;
    for(i=a+b-1;i>0;i--){
		if(c[i]>=10){c[i-1]=c[i-1]+c[i]/10;c[i]=c[i]%10;}
	}    
	 return c;
	
}
int* power(int *a,int size,int n)
{    
	if(n==1){ return a;}
	else{
	return  mult(a,size, power(a, size, n-1),size*(n-1));}
	
}




void main()
{
	char b[7]="000000";
	int *s;
	int n;
	while(cin>>b>>n){
		int i,j=0,k,t,h;
	if(n==1){double d=atof(b);cout<<d; }
	if(n!=1){
		s=new int[strlen(b)];
	for(i=0;i<int(strlen(b));i++){
		if(b[i]!='.'){s[j]=b[i]-'0';j++;}
		if(b[i]=='.'){k=strlen(b)-i-1;}
	}
	int *c;
	c=new int[int(strlen(b)-1)*n];
	for(i=0;i<int(strlen(b))*n;i++){c[i]=0;}
    c=power(s,int(strlen(b))-1,n);
	for(t=0;t<n&&(c[t]==0);t++){t=t;}
	for(h=int(strlen(b)-1)*n-1;h>0&&(c[h]==0);h--){h=h;}
	for(i=t;i<=h;i++)
	{if(i==int(strlen(b)-1)*n-k*n){cout<<".";}cout<<c[i];}
	delete[]c;
	delete[]s;}
	cout<<endl;}


}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -