蓝桥杯-卡片-填空题
·
一:题目

二:思路
1是最快消耗完的计算1的个数即可
三:上码
#include <iostream>
using namespace std;
int main()
{
int ans = 0;
int count = 0;
for(int i = 1; i < 20000; i++) {
string str = to_string(i);
// cout << str << endl;
for(int j = 0; j < str.size(); j++) {
int nums = str[j] - '0';
if(nums == 1) {
count++;
if(count == 2021) {
ans = i;
break;
}
}
}
}
cout << ans;
}

更多推荐



所有评论(0)