R格式 (15届B) 高精度

cpp 复制代码
#include<bits/stdc++.h>
using namespace std;

void mul(vector<int> &A,int b)
{
	int t=0;
	for(int i=0;i<A.size();i++)
	{
		t+=A[i]*b;
		A[i]=t%10;
		t/=10;
		}
		if(t) A.push_back(t);
}

void add(vector<int >& A, int k,int b)
{
	int t=b;
	for(int i=k;i<A.size();i++)
	{
		t+=A[i];
		A[i]=t%10;
		t/=10;
	}
	if(t) A.push_back(t);
}


int main()
{
	int n;
	string d;
	cin>>n>>d;
	
	reverse(d.begin(),d.end());
	int dot=d.find('.');
	vector<int> D;
	for(auto c:d)
	 	if(c!='.')
	 	D.push_back(c-'0');
	
	while(n--) mul(D,2);
	if(D[dot-1]>=5) add(D,dot,1);
	for(int i=D.size()-1;i>=dot;i--)
	cout<<D[i];
	return 0;
}
相关推荐
不知天地为何吴女士30 分钟前
Day32| 509. 斐波那契数、70. 爬楼梯、746. 使用最小花费爬楼梯
算法
小坏坏的大世界30 分钟前
C++ STL常用容器总结(vector, deque, list, map, set)
c++·算法
wjs20241 小时前
状态模式(State Pattern)
开发语言
我命由我123451 小时前
Kotlin 数据容器 - List(List 概述、创建 List、List 核心特性、List 元素访问、List 遍历)
java·开发语言·jvm·windows·java-ee·kotlin·list
liulilittle1 小时前
C++ TAP(基于任务的异步编程模式)
服务器·开发语言·网络·c++·分布式·任务·tap
励志要当大牛的小白菜3 小时前
ART配对软件使用
开发语言·c++·qt·算法
qq_513970443 小时前
力扣 hot100 Day56
算法·leetcode
Chef_Chen4 小时前
从0开始学习R语言--Day55--弹性网络
r语言
PAK向日葵4 小时前
【算法导论】如何攻克一道Hard难度的LeetCode题?以「寻找两个正序数组的中位数」为例
c++·算法·面试
爱装代码的小瓶子5 小时前
数据结构之队列(C语言)
c语言·开发语言·数据结构