A - 高精度(大数)N次方(第二季水)
Description
This problem requires that you write a program to compute the exact value of R n where R is a real number ( 0.0 < R < 99.999 ) and n is an integer such that 0 < n <= 25.
Input
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
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
char a[];
int n;
while(cin>>a>>n){
int b=,c[]={},i,j,x,flag=;
c[]=;
for(i=;a[i]!='\0';i++)
{
if(a[i]=='.')
{
x=i; //x为小数点所在的位置
flag=;
continue;
}
b=b*+a[i]-''; //b为a[10]去掉小数点后的整型数字
}
x=i-x-; //x为小数部分的位数
for(i=;i<n+;i++)
{
for(j=;j<;j++)
c[j]*=b;
for(j=;j>=;j--)
if(c[j]>=)
{
c[j-]+=c[j]/;
c[j]%=;
}
}
if(flag==)
{
for(i=;c[i]==;i++); //i为c[250]中才首位开始判断 不是0的那一位
for(;i<;i++)
cout<<c[i]; //无小数部分时直接输出c[250],无需考虑小数点
}
else if(a[]=='') //只有小数部分时
{
flag=;
//整数部分为0,不输出
for(j=i;j<;j++)
if(c[j]!=)
{
flag=;
break; //利用flag的值来判断结果是否存在小数部分
}
if(flag==)
{
cout<<".";
for(j=;c[j]==&&j>=i;j--); //去掉小树部分最后多余的0
for(i=-n*x;i<=j;i++)
cout<<c[i];
}
}
else //既有小数部分也有整数部分
{
flag=;
for(i=;c[i]==;i++);
for(;i<-n*x;i++) //小数部分一共是n*x位,之前全为整数部分
cout<<c[i];
for(j=i;j<;j++)
if(c[j]!=)
{
flag=;
break; //此处 同上述只有小数部分的情况
}
if(flag==)
{
cout<<".";
for(j=;c[j]==&&j>=i;j--);
for(;i<=j;i++)
cout<<c[i];
} }
cout<<endl;
}
system("pause");
return ;
}
A - 高精度(大数)N次方(第二季水)的更多相关文章
- F - The Fun Number System(第二季水)
Description In a k bit 2's complement number, where the bits are indexed from 0 to k-1, the weight o ...
- D - Counterfeit Dollar(第二季水)
Description Sally Jones has a dozen Voyageur silver dollars. However, only eleven of the coins are t ...
- S - 骨牌铺方格(第二季水)
Description 在2×n的一个长方形方格中,用一个1× 2的骨牌铺满方格,输入n ,输出铺放方案的总数. 例如n=3时,为2× 3方格,骨牌的铺放方案有三种, ...
- R - 一只小蜜蜂...(第二季水)
Description 有一只经过训练的蜜蜂只能爬向右侧相邻的蜂房,不能反向爬行.请编程计算蜜蜂从蜂房a爬到蜂房b的可能路线数. 其中,蜂房的结构如下所示. ...
- I - Long Distance Racing(第二季水)
Description Bessie is training for her next race by running on a path that includes hills so that sh ...
- Y - Design T-Shirt(第二季水)
Description Soon after he decided to design a T-shirt for our Algorithm Board on Free-City BBS, XKA ...
- N - Robot Motion(第二季水)
Description A robot has been programmed to follow the instructions in its path. Instructions for the ...
- B - Maya Calendar(第二季水)
Description During his last sabbatical, professor M. A. Ya made a surprising discovery about the old ...
- T - 阿牛的EOF牛肉串(第二季水)
Description 今年的ACM暑期集训队一共有18人,分为6支队伍.其中有一个叫做EOF的队伍,由04级的阿牛.XC以及05级的COY组成.在共同的集训生活中,大家建立了深厚的 ...
随机推荐
- weblogic开机启动脚本
1.在/home/bea/startBeaAll目录内创建一个startBeaAll.sh文件,加入如下内容(把相应目录与命令修改即可,红字部分为修改地方): #!/bin/sh echo " ...
- Struts2中的校验框架
Struts2提供的客户端校验 尽管这种支持比较弱,但采用Struts2中的客户端校验时需要注意以下几点 1..将<s:form validate="true">的va ...
- (转)ubuntu下如何查看软件安装目录以及安装版本
1.查询版本 aptitude show 软件名 例如:aptitude show kde-runtime 显示如下: ****@ubuntu:~$ aptitude show kde-runtime ...
- GitHub+hexo to Blog
title: GitHub+hexo to Blog date: 2014-12-26 09:44:53 tags: hexo, github --- 摘要 一直想要一个自己的博客,不过一直怯于对网站 ...
- mysql按月,按日分组统计数据
group by DATE_FORMAT(createtime,'%Y-%m');//按月统计数据 group by DATE_FORMAT(createtime,'%Y-%m-%d');//按天统计 ...
- Unity3d Web Player 的server端联网配置
新游戏出了第一个能跑完流程的版本,不得不佩服Unity3D强大的功力,PC.MAC OS.Linux.IOS.Android.web player,前天刚发布的unity3d 4.2版本还支持WIND ...
- 3D Touch:静态快速启动方式
原文传送门:Add iOS 9’s Quick Actions shortcut support in 15 minutes right now ! 苹果在iOS9 上引入3D触控(压力触控)功能 ...
- ASP.NET用户自定义控件配置
一直以来开发中碰到要写自定义控件的时候总是习惯性的找度娘,而没有自己记住,结果今天就悲剧了,找了半天才找到,想想还是自己积累起来吧! 第一种配置方式: 配置写在webconfig文件中,位置如下: w ...
- BZOJ 3576 江南乐
http://www.lydsy.com/JudgeOnline/problem.php?id=3576 思路:由于数字巨大,因此N^2异或做法是过不了的,我们考虑将n个石子分成i堆,那么会有n%i堆 ...
- C# 获取当前应用程序的绝对路径支持asp.net
Asp.net在类库中获取某文件的绝对路径.这个问题在初学的时候就经常碰到过,经常是查了忘,忘了查.浪费了大量的今天专门写个文章,以后到这里查.有时间顺便记得研究下这个东西. 在主程序目录就不说了 ...