Initial commit
This commit is contained in:
34
15lanqiao/test4.cpp
Normal file
34
15lanqiao/test4.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
#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
|
||||
*/
|
||||
Reference in New Issue
Block a user