Files
lanqiao/15lanqiao/test4.cpp
2025-03-20 19:03:56 +08:00

35 lines
941 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 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] = 4a[2] = 1a[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] = 6a[2] = 5a[3] = 2a[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
*/