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组成.在共同的集训生活中,大家建立了深厚的 ...
随机推荐
- PHP学习笔记三十【final】
<?php //final不能去修饰属性(变量) //如果希望类不希望被继承就可以使用final关键字 final class Person() { public function sayHi( ...
- iOS-OC-基础-NSDictionary常用方法
/*=============================NSDictionary(不可变字典)的使用=========================*/ //————————————————— ...
- 仿QQ好友列表界面的实现
TableView有2种style:UITableViewStylePlain 和 UITableViewStyleGrouped. 但是QQ好友列表的tableView给人的感觉似乎是2个style ...
- for循环执行顺序
for循环的执行顺序用如下表达式: for(expression1;expression2;expression3) { expression4; } 执行的顺序应该是: 1)第一次循环,即初始化循环 ...
- (转)android ndk 给结构体赋值的方法
转自:http://www.cnweblog.com/fly2700/archive/2012/03/21/320083.html 1,java 代码 结构体定义 public class Media ...
- LaTeX使用titlesec宏包改变章节编号形式的方法
1.titleformat宏包命令详解 LaTeX中可以用titlesec宏包中的titleformat命令来改变标题形式: 导入宏包: \usepackage{titlesec} 改变标题的代码如下 ...
- opencv for python
opencv显示图像: # -*- coding: UTF-8 -*- import numpy as np import cv2 from matplotlib import pyplot as p ...
- iOS开发之OC篇-响应式编程Reactive Cocoa
一.Reactive Cocoa 介绍 Reactive Cocoa 是 iOS 开发的一个 "重量级" 框架 高大上的概念:响应式编程 核心概念:信号 Signal 官方网站:h ...
- jQuery之位置
1.offset()获取匹配元素在相对浏览器窗口的偏移量 返回一个对象,包括两个属性.left:相对浏览器窗口左边的距离.top:相对浏览器顶部的距离. $("#div1").o ...
- Python打印格式化与字符串
关于Python打印格式化与字符串,比较全面的总结,希望对大家有帮助~ # -*- coding: cp936 -*- ''' 打印格式 ''' print "a" print & ...