#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
using namespace std;
#ifndef BIGN_H_INCLUDED
#define BIGN_H_INCLUDED
#define MAX_N 3000 //最大位数
//大数
struct bign {
char s[MAX_N];
int len;
bign() {
memset(s, 0, sizeof(s));
len = 1;
}
bign(int num) {
*this = num;
}
bign(const char *num) {
*this = num;
}
bign operator = (const char *num) {
len = strlen(num);
for(int i=0; i<len && num[len-1-i]>='0' && num[len-1-i]<='9'; i++) {
s[i] = num[len-1-i] - '0';
}
while(s[len-1] == 0) len--;
return *this;
}
bign operator = (int num) {
char s[MAX_N];
sprintf(s, "%d", num);
*this = s;
return *this;
}
bign operator + (const bign &b) const
{
bign c;
int m = len > b.len ? len : b.len;
int i, g, sum;
for(i=0, g=0; g || i< m; i++) {
sum = g;
if(i < len) sum += s[i];
if(i < b.len) sum += b.s[i];
c.s[i] = sum%10;
g = sum / 10;
}
c.len = i;
return c;
}
bign operator += (const bign &b)
{
*this = *this + b;
return *this;
}
bign operator * (const bign &b) const
{
bign c;
int i, j, g, sum;
for(i=0; i<b.len; i++) {
g = 0;
for(j=0; g||j<len; j++) {
sum = c.s[i+j] + g;
if(j < len) sum += b.s[i]*s[j];
c.s[j+i] = sum % 10;
if(c.s[j+i] > 0) c.len = i+j+1;
g = sum / 10;
}
}
return c;
}
bign operator *= (const bign &b)
{
*this = *this * b;
return *this;
}
bool operator < (const bign &b) const
{
if(b.len != len) return len < b.len;
int i;
for(i=len-1; i>=0; i--) {
if(s[i] != b.s[i]) return s[i] < b.s[i];
}
return false;
}
bool operator > (const bign &b) const { return b < *this;}
bool operator <= (const bign &b) const {return !(*this > b);}
bool operator >= (const bign &b) const {return !(*this < b);}
bool operator != (const bign &b) const {return (*this < b) || (*this > b);}
bool operator == (const bign &b) const {return !(*this < b) && !(*this > b);}
};
ostream& operator << (ostream& outstream, const bign& b)
{
for(int i=b.len-1; i>=0; i--) {
outstream << (int)b.s[i] << "";
}
return outstream;
}
istream& operator >> (istream& instream, bign& b)
{
string s;
instream >> s;
b = s.c_str();
return instream;
}
//实数
struct real {
bign _b; //保证末尾不为0
unsigned int _dot;
real(const bign b, const unsigned int dot) {
_b = b;
_dot = dot;
}
};
ostream& operator << (ostream& outstream, const real& r)
{
int i = r._dot - r._b.len;
int j;
if(i >= 0) {
outstream << ".";
for(j=0; j<i; j++) {
outstream << "0";
}
outstream << r._b;
} else {
int l = r._b.len - 1;
for(j=0; j>i; j--) {
outstream << (int)r._b.s[l--];
}
if(l >= 0) outstream << ".";
while(l >= 0) {
outstream << (int)r._b.s[l--];
}
}
return outstream;
}
#endif // BIGN_H_INCLUDED
char d[100];
int n;
#define MAX_INT ((1u<<(sizeof(int)*8-1))-1)
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif
char *p, *q;
int i, l, sum_dot, dot;
bign a, sum;
while(scanf("%s %d", d, &n) == 2) {
//printf("%s %d\n", d, n);
l = strlen(d);
p = strchr(d, '.');
dot = l - (p - d) - 1; //小数位数
q = p;
while(*(++p)) { //去除末尾0
if(*p != '0') q = p;
*(p-1) = *p;
}
*q = 0;
if(q-d < l-1) {
dot -= l-1 - (q-d);
}
a = d;
sum = 1;
sum_dot = 0;
for(i=0; i<n; i++) {
sum *= a;
sum_dot += dot;
}
real r(sum, sum_dot); //生成实数
cout << r << endl;
}
}
UVa 748 Exponentiation
最新推荐文章于 2021-05-25 21:25:42 发布