题目描述: 找出1 - N中能被5整除且至少有一位数字是5的所有整数的个数。
输入:输入只有一行,包括1个整数N。(N<32767)
输出:输出只有一行(这意味着末尾有一个回车符号),包括1个整数,表示符合条件的数 的个数。
样例1:输入
22
样例1:输出
2
要求: 时间限制: 1.0Sec内存限制:128MB
代码如下:
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n,s=0;
cin>>n;
for(int i=1;i<=n;i++)
{
int f=0;
if(i%5==0)
{
f=1;
}
int t=i;
while(t!=0)
{
int g=t%10;
if(g==5)
{
if(f==1)
{
s+=1;
break;
}
}
t=t/10;
}
}
cout<<s<<endl;
return 0;
}