蓝桥杯B15-4,R格式

cpp 复制代码
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main() {
    vector<char>v;
    int n,tag;
    string d;
    cin >> n >> d;
    for (int i = d.size() - 1; i >= 0;i--) {
        if (d[i] != '.') {
            v.push_back(d[i]-'0');
        }
        else {
            tag = i;
        }
    }
    tag = d.length() - tag - 1;
    for (int i = 0; i < n;i++) {
        int tmp = 0;
        for (int j = 0; j < v.size();j++) {
            v[j] *= 2;
            v[j] += tmp;
            tmp = v[j] / 10;
            v[j] %= 10;
        }
        if (tmp) {
            v.push_back(tmp);
        }
    } 
    if (v[tag - 1] >= 5) {
        v[tag] += 1;
    }
    for (int i = v.size() - 1; i >= tag; i--) {
        cout << int(v[i]);
    }
    return 0;
}
相关推荐
郝学胜-神的一滴2 小时前
Leetcode 969 煎饼排序✨:翻转间的数组排序艺术
数据结构·c++·算法·leetcode·面试
I_LPL9 小时前
hot100贪心专题
数据结构·算法·leetcode·贪心
颜酱9 小时前
DFS 岛屿系列题全解析
javascript·后端·算法
WolfGang00732110 小时前
代码随想录算法训练营 Day16 | 二叉树 part06
算法
2401_8318249611 小时前
代码性能剖析工具
开发语言·c++·算法
Sunshine for you12 小时前
C++中的职责链模式实战
开发语言·c++·算法
qq_4160187212 小时前
C++中的状态模式
开发语言·c++·算法
2401_8845632412 小时前
模板代码生成工具
开发语言·c++·算法
2401_8319207412 小时前
C++代码国际化支持
开发语言·c++·算法
m0_6727033112 小时前
上机练习第51天
数据结构·c++·算法