小蓝有很多数字卡片,每张卡片上都是数字 00到 99。 小蓝准备用这些卡片来拼一些数,他想从 11 开始拼出正整数,每拼一个, 就保存起来,卡片就不能用来拼其它数了。 小蓝想知道自己能从 11 拼到多少。 例如,当小蓝有 3030 张卡片,其中 00 到 99 各 33 张,则小蓝可以拼出 11到 1010, 但是拼 1111 时卡片 11 已经只有一张了,不够拼出 1111。 现在小蓝手里有 00 到 99 的卡片各 20212021 张,共 2021020210 张,请问小蓝可以从 11 拼到多少? 提示:建议使用计算机编程解决问题。
#include<stdio.h>
int sum(int n){
int count=0;
int temp;
while(n>0){
temp=n%10;
n=n/10;
if(temp==1){
count++;
}
}
return count;
}
int main(){
int sum(int n);
int n,c;
int i=1;
c=0;
for(i=1;i<5000;i++){
c=c+sum(i);
if(c==2021){
printf("%d",i);
}
}
return 0;
}