一:题目

在这里插入图片描述

二:思路

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;
	
	
} 

在这里插入图片描述

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐