题解 | #规律数列求和#

规律数列求和

https://www.nowcoder.com/practice/e05d1c142b3d4898be7183289a00ce5f

#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {

    // write your code here......
    long sum = 0;
    int maxBitNum = 10;
    for (int i=1; i<=maxBitNum; i++) {
        // std::vector<char> vc;
        std::string res;
        for (int j=1; j<=i; j++) {
            // vc.push_back('9');
            res += "9";
        }
        // res.insert(res.begin(), vc.begin(), vc.end());
        long targetValue = stol(res, 0, 10);
        sum += targetValue;
    }

    cout << sum << endl;

    return 0;
}

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务