题目
输入数字n,按顺序打印出从1最大的n位十进制数。比如输入3,则打印出1、2、3一直到最大的3位数即999。要考虑大数问题
大数加法,乘法详解:https://www.cnblogs.com/tianzeng/p/9020822.html
解法
用字符串或者数组表达大数
- 把字符串中的每一个数字都初始化为'0';
- 每一次为字符串表示的数字加1,再打印出来;
#include <iostream> #include <vector> using namespace std; class Solution { public: void to_print_max_num(int n); bool increment(vector<char> &s); void print(vector<char> &s); }; void Solution::to_print_max_num(int n) { if(n<=0) return; vector<char> s(n,'0'); s[n]='