35 lines
941 B
C++
35 lines
941 B
C++
// lanqiao 19710 R 格式
|
||
#include<bits/stdc++.h>
|
||
using namespace std;
|
||
const int N = 2e3 + 10;
|
||
string s; int a[N];
|
||
int main() {
|
||
int n; cin >> n >> s;
|
||
reverse(s.begin(), s.end());
|
||
int pos = s.find("."); // 小数点位置
|
||
s.erase(pos, 1); // 删除小数点, 方便后续计算
|
||
int len = s.size();
|
||
for(int i = 0; i < len; i++) a[i+1] = s[i] - '0';
|
||
// a[1] = 4,a[2] = 1,a[3] = 3
|
||
|
||
//高精度*低精度模版
|
||
for(int i = 1; i<=n; i++){
|
||
// 顺序扫描每一位, 均乘2
|
||
for(int j = 1; j <= len; j++) a[j] *= 2;
|
||
for(int j = 1; j <= len; j++){
|
||
if(a[j] > 10){
|
||
a[j+1]++;
|
||
a[j] %= 10;
|
||
if(j == len) len++;
|
||
}
|
||
}
|
||
}
|
||
// a[1] = 6,a[2] = 5,a[3] = 2,a[4] = 1 a[pos] = 5
|
||
if(a[pos] >= 5) a[pos+1]++;
|
||
for(int i = len; i >= pos + 1; i--) cout << a[i];
|
||
cout << endl;
|
||
return 0;
|
||
}
|
||
/*
|
||
2 3.14
|
||
*/ |