模拟高精度乘法也可,n次乘2就行了
#include <bits/stdc++.h>
using namespace std;
int up[1000000],newbit;
int main(){
int n;
string s;
cin>>n>>s;
int p;
string tmp="";
for(int i=s.length()-1;i>=0;i--){
if(s[i]=='.'){
p=s.length()-1-i;
}else tmp+=s[i];
}
s="";
for(int i=tmp.length()-1;i>=0;i--){
s+=tmp[i];
}
while(n--){
for(int i=s.length()-1;i>=0;i--){
s[i]+=s[i]-'0';
if(s[i]>'9'){
s[i]-=10;
if(i!=0)
up[i-1]++;
else newbit++;
}
}
for(int i=s.length()-1;i>=0;i--){
if(up[i]){
s[i]+=up[i];
up[i]=0;
if(s[i]>'9'){
s[i]-=10;
if(i!=0)
up[i-1]++;
else newbit++;
}
}
}
if(newbit){
s=to_string(newbit)+s;
newbit=0;
}
}
stack<char>back,pre;
for(int i=s.length()-1;i>=0;i--){
if(p){
p--;
back.push(s[i]);
}else{
pre.push(s[i]);
}
}
int res=0;
int cnt=2;
while(back.size() and cnt){
res*=10;
res+=back.top()-'0';
back.pop();
cnt--;
}
string ans="";
while(pre.size()){
ans+=pre.top();
pre.pop();
}
if(res>=50){
ans[ans.length()-1]++;
int getup=0;
for(int i=ans.length()-1;i>=0;i--){
if(getup){
ans[i]++;
getup=0;
}
if(ans[i]=='9'+1){
ans[i]='0';
getup++;
}
}
if(getup){
ans="1"+ans;
}
}
cout<<ans;
return 0;
}
2 回复
0 转发
0 喜欢
12 阅读



