敲七

敲七

Problem
输出7和7的倍数,还有包含7的数字例如(17,27,37...70,71,72,73...) 

Input
一个整数N。(N不大于30000) 

Output
从小到大排列的不大于N的与7有关的数字,每行一个。 

Sample Input
20

Sample Output
7
14
17
#include<iostream>
using namespace std;

int main()
{
    int n;
    cout<<"please input the number:";
    cin>>n;
    
    int x=n;
    int m=1;//n的位数
    while(x/10!=0)
    {
        m++;
        x=x/10;
    }
    for(int i=1;i<=n;i++)
    {
        int a[4];
        int z=1;
        int y=i;
        for(int j=0;j<m;j++)
        {
            //应该从最低位依次取
            z=z*10;
            a[j]=y%z;
            y=y/10;
        }
        if((i%7==0))
        {
            cout<<i<<endl;
        }
        else
        {
            for(int j=0;j<m;j++)
            {
                if(a[j]==7)
                {
                    cout<<i<<endl;
                    break;
                }
            }
        }
    }
    return 0;
}
原文地址:https://www.cnblogs.com/coder2012/p/2713300.html