Problem F: Exponentiation
Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 4 Solved: 2
[Submit][Status][Web Board] [Edit] [TestData]
Description
Problems involving the computation of exact values of very large magnitude and precision are common. For example, the computation of the national debt is a taxing experience for many computer systems.

This problem requires that you write a program to compute the exact value of Rn where R is a real number ( 0.0 < R < 99.999) and n is an integer such that $0 < n \le 25$.

Input
The input will consist of a set of pairs of values for R and n. The R value will occupy columns 1 through 6, and the n value will be in columns 8 and 9.

Output
The output will consist of one line for each line of input giving the exact value of Rn. Leading zeros and insignificant trailing zeros should be suppressed in the output.

Sample Input
95.123 12
0.4321 20
5.1234 15
6.7592 9
98.999 10
1.0100 12
Sample Output
548815620517731830194541.899025343415715973535967221869852721
.00000005148554641076956121994511276767154838481760200726351203835429763013462401
43992025569.928573701266488041146654993318703707511666295476720493953024
29448126.764121021618164430206909037173276672
90429072743629540498.107596019456651774561044010001
1.126825030131969720661201
主要思路是:几的几次方。实际上也就是大数相乘,先把小数点去掉,然后相乘,最后再把小数点加上。比如说的 a 的 n 次方,那先把字符数组a里面的东西,赋值给字符数组b,然后 a 和 b 进行运算,乘的结果放到sum数组里,然后整型的 sum 数组里的每个元素转换成字符型的,赋值给字符数组b,然后再和 a数组运算,运算的次数和你输入的几次方有关系。。然后再进行细节方面的问题……

#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
int main()
{
char a[];
char b[];//和字符数组a一样的
int n,i,j,k,lena,lenb,g,g1,h,ji1,ji2;
int sum[];
char s[];
while(scanf("%s%d",&a,&n)!=EOF)
{
if(n==)
cout<<a<<endl;
else
{
int count=;
memset(sum,,sizeof(sum));
lena=strlen(a);
for(i=;i<lena;i++)
{
if(a[i]=='.')
{
count=lena-i-;//小数点后面几位
for(j=i;j<lena-;j++)
{
a[j]=a[j+];
}
a[j]='\0';
lena--; //变成没有小数点的数
break;
}
}
count=count*n;//经过处理小数点最终有count位
for(i=;i<lena;i++)
{
b[i]=a[i];
}
b[i]='\0';
lenb=strlen(b);
for(i=;i<=n-;i++)
{
memset(sum,,sizeof(sum));
g=;g1=;
for(j=lenb-;j>=;j--)//下面的乘数
{
for(k=lena-;k>=;k--)//上面的乘数
{
sum[g--]+=(a[k]-'')*(b[j]-'');
}
g1--;
g=g1;
}
for(k=;k>=;k--)
{
sum[k-]+=sum[k]/;
sum[k]=sum[k]-sum[k]/*;
}
int start=;
int l=;
while(!sum[start] &&start<=)
start++;
for(h=start;h<=;h++)
{
b[l++]=sum[h]+'';
}
b[l]='\0';
lenb=strlen(b);
}
if(count!=)
{
for(g=;g<=;g++)
s[g]=sum[g]+'';
s[]='\0';
for(i=;i>-count;i--)
s[i+]=s[i];
s[i+]='.';
for(i=;i<=;i++)
{
if(s[i]!='')
{
ji1=i;
break;
}
}
for(i=;i>=;i--)
{
if(s[i]!='')
{
ji2=i;
break;
}
}
for(i=ji1;i<=ji2;i++)
cout<<s[i];
cout<<endl;
}
else
cout<<b<<endl;
}
}
return ;
}

Problem F: Exponentiation的更多相关文章

  1. Problem F: Exponentiation大数求幂

    DescriptionProblems involving the computation of exact values of very large magnitude and precision ...

  2. 实验12:Problem F: 求平均年龄

    Home Web Board ProblemSet Standing Status Statistics   Problem F: 求平均年龄 Problem F: 求平均年龄 Time Limit: ...

  3. The Ninth Hunan Collegiate Programming Contest (2013) Problem F

    Problem F Funny Car Racing There is a funny car racing in a city with n junctions and m directed roa ...

  4. Codeforces Gym 100500F Problem F. Door Lock 二分

    Problem F. Door LockTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100500/at ...

  5. Codeforces Gym 100002 Problem F "Folding" 区间DP

    Problem F "Folding" Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/ ...

  6. Codeforces Gym 100286F Problem F. Fibonacci System 数位DP

    Problem F. Fibonacci SystemTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudg ...

  7. Problem F: 合唱比赛开始了!

    Problem F: 合唱比赛开始了! Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 440  Solved: 201[Submit][Status][ ...

  8. 几何入门合集 gym101968 problem F. Mirror + gym102082 Problem F Fair Chocolate-Cutting + gym101915 problem B. Ali and Wi-Fi

    abstract: V const & a 加速 F. Mirror 题意 链接 问题: 有n个人在y=0的平面上(及xoz平面).z=0平面上有一面镜子(边平行于坐标轴).z=a平面上有q个 ...

  9. Problem F Plug It In!

    题目链接:https://cn.vjudge.net/contest/245468#problem/F 大意:给你插座和电器的对应关系,有多个电器对应一个插座的情况,但是一个插座只能供一个电器使用,现 ...

随机推荐

  1. C++默认参数与函数重载 注意事项

    一.默认参数在C++中,可以为参数指定默认值.在函数调用时没有指定与形参相对应的实参时, 就自动使用默认参数. 默认参数的语法与使用:(1)在函数声明或定义时,直接对参数赋值.这就是默认参数:(2)在 ...

  2. IE8 多进程问题

    IE8的一个重要特性就是每个Tab(选项卡)在独立的进程中运行,我们称之为LCIE(Loosely-Coupled IE). 所以大家在升级到IE8之后会发现资源管理器里面有两个或者多个iexplor ...

  3. NOI2013 Day2

    NOI2013 Day2 矩阵游戏 题目描述:设矩阵\(F\) 求\(F[n][m](mod (10^9+7))\) solution: 这题可以求通项解决. 设\(X_i=F[i][m]\), \( ...

  4. golang仿AS3写的ByteArray

    用golang写了个仿AS3写的ByteArray,稍微有点差别,demo能成功运行,还未进行其他测试 主要参考的是golang自带库里的Buffer,结合了binary 来看看demo: packa ...

  5. Vxlan 原理

    https://www.gitbook.com/book/yeasy/openstack_understand_neutron/details 自己总结一下: 分析 VTEP的情况, 即Vxlan跟V ...

  6. uva 10003 Cutting Sticks (区间dp)

    本文出自   http://blog.csdn.net/shuangde800 题目链接:  打开 题目大意 一根长为l的木棍,上面有n个"切点",每个点的位置为c[i] 要按照一 ...

  7. js判断终端是手机还是电脑

    $(function(){ function browserRedirect() { var sUserAgent= navigator.userAgent.toLowerCase(); var bI ...

  8. How to Type(dp)

    How to Type Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tota ...

  9. java入门学习(九) 算术运算符

    请大家关注我的博客www.taomaipin.com 运算符在java基础中也占有着举足轻重的位置,我们当然要学会它.java 其实和其他计算机语言一样,基本的算术运算符基本一样,让我们看看 有哪些算 ...

  10. 软件介绍:搜索工具 Listary

    如今的互联网时代,搜索的重要性我想大家都是认可的.网上的知识浩如烟海,而搜索引擎是通向这些知识的入口.谷歌.百度等搜索引擎给我们带来了极大的便利,也无怪他们成长为如今的互联网巨头. 然而储存在个人硬件 ...