您的位置:首页 > 科技 > 能源 > 优设网官网app_成都网站seo收费标准_信息流优化师证书_抖音关键词排名推广

优设网官网app_成都网站seo收费标准_信息流优化师证书_抖音关键词排名推广

2025/5/3 2:11:32 来源:https://blog.csdn.net/xzal12/article/details/147548734  浏览:    关键词:优设网官网app_成都网站seo收费标准_信息流优化师证书_抖音关键词排名推广
优设网官网app_成都网站seo收费标准_信息流优化师证书_抖音关键词排名推广

题目:

编写程序,计算区间100~n之间的所有整数(100<n<=999),数字x(0<x<9)共出现的次数。

例如:100到109中,即100、101、102、103、104105106107108109中,数字1出现了11次。

//方法一:
#include <iostream>
using namespace std;
int main(){int n,x;int count=0;cin >> n >> x;int g=0,s=0,b=0;for(int i=100;i<=n;i++){g=i%10;s=i/10%10;b=i/10/10%10;if(g==x)count+=1;	if(s==x)count+=1;	if(b==x)count+=1;	}cout << count;return 0;
}
//方法二:
#include <iostream>
using namespace std;
int main(){int n,x;int count=0;cin >> n >> x;for(int i=100;i<=n;i++){int tmp = i;while(tmp){int gewei=tmp%10;tmp /= 10;if(gewei==x)count+=1;		}}cout << count;return 0;
} 

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com