链接:https://ac.nowcoder.com/acm/problem/22168
来源:牛客网
题目描述
求出a到b之间有多少个数数位之和为5的倍数
输入描述:
输入一行包含两个整数x,y (0 \le x, y \le 10000000≤x,y≤1000000)
输出描述:
输出一个整数
示例1
输入
复制
10 20
输出
复制
2
说明
14和19的数位和为5和10,符合条件
答案如下:
#include<bits/stdc++.h>
using namespace std;
int store[20];
bool judge(int x)
{
int i=0,sum=0;
while(x)
{
store[i]=x%10;
i++;
x/=10;
}
for(int j=0;j<i;j++)
{
sum+=store[j];
}
if(sum%5==0) return true;
else return false;
}
int main()
{
int a,b,an=0;
cin>>a>>b;
for(int i=a;i<=b;i++)
{
if(judge(i))
an++;
}
cout<<an;
return 0;
}