数位拆分
2026-04-26 09:51:48
发布于:湖北
2阅读
0回复
0点赞
注意f=1要放在循环内
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;int shuwei;int count=0;int f;
cin>>n;
for(int i=1;i<=n;i++){
int shuzi = i;
int temp = shuzi%10; //定义临时变量
f=1;
while(shuzi>0){
shuwei = shuzi%10;
if(shuwei!=temp){
f=0;
break;
}
shuzi/=10;
}
if(f==1) count++;
}
cout<<count;
return 0;
}
这里空空如也



有帮助,赞一个