葫芦岛网站建设,松江区网站制作与推广,四川建设网站电子招标,网站建设算研发费用吗1、题目 输入一个十进制的数#xff0c;输出 #xff08;1#xff09;、给定n#xff0c;求出从1到n的所有整数中1的个数。#xff08;暂用用f(n)表示#xff09; #xff08;2#xff09;、求满足nf(n)的最小整数#xff08;1除外#xff09;。 #include ios…1、题目 输入一个十进制的数输出 1、给定n求出从1到n的所有整数中1的个数。暂用用f(n)表示 2、求满足nf(n)的最小整数1除外。 #include iostream #include math.h using namespace std; void solve(); int input(); int power(int count); void main(){ solve(); system(pause); } void solve(){ int n,count0,i,sum0; ninput(); //count为一个计数的来计算n是几位数如1则为个位数2则为百位数 in; while(i){ ii/10; count; } while(count--){ i(n/power(count))%10;//提取了与count对应的位 coutiendl; if(i1){ if(0count)//如果对应个位 sum1; else sumn%power(count)1; } else if(i1){ sumpower(count); } sumn/power(count1)*power(count); } cout一个有sum个1endl; } int input(){ cout请输入您想要输入的数字:endl; int n; cinn; return n;} int power(int count){ int m1; if(count0){ coutcount值有误endl; return -1; } else while(count--) m*10; return m; } 把每个位置上的数都分离出来先确定是几位数然后在利用每个位置上的数求得出现多少个1 。 总结要学会变换思路以前的时候通过列举找规律遇到这个问题的时候例句明显太麻烦了而且很难找到规律可以找一个数来拆解。转载于:https://www.cnblogs.com/jump/p/4548435.html