题目
【题意】
思路:用字母j来表示现在数字大小,i表示去掉忽略的数字的报数个数;有几个判断过程:数字是7的倍数需要略过,以及数字中包含数字7需要略过。着重来看一下数字中包含数字7的数字们,如果是十位数字用n=n/10只留下十位数字大小如果个位数字n%10==7则返回true,其他时候返回false。
我写的时候忘记返回false最后运行时间超时有点尴尬哈哈哈。
【代码】:
```cpp
#include<iostream>
#include<algorithm>
using namespace std;
int n;
int a,b,c,d;//甲、乙、丙、丁
bool jump(int n)
{
if(n%7 == 0)
return true;
while(n>0)
{
if(n%10==7)//10以内个位数是7
return true;
n = n/10;//保留十位数组
}
return false;
}
int main()
{
cin>>n;
int i=1,j=1;
while(i<=n)
{
if(jump(j))
{
if(j%4 == 1) a++;
else if(j%4 ==2) b++;
else if(j%4 == 3) c++;
else if(j%4 == 0) d++;
}
else
i++;
j++;
}
cout<<a<<endl;
cout<<b<<endl;
cout<<c<<endl;
cout<<d<<endl;
}
``
【总结】:
处理数字的时候可以用n=n/10;