天天看點

找數字個數

連結:​​https://www.nowcoder.com/acm/contest/67/I​​ 來源:牛客網

題目描述

    lulu喜歡小于等于1000的正整數,但是如果某個數是a或b的倍數,lulu會讨厭這個數。如果某個數裡包含了a和b兩個數裡包含的數,lulu也會讨厭。(例如a=14,b=23,如果數字中包含1、2、3、4這四個數中的任意一個數,lulu就會讨厭這個數)。現在告訴你a,b,你能說出lulu喜歡的數有多少個麼。

輸入描述:

第一行是樣例數T

第2到2+T-1行每行有2個整數a b。

輸出描述:

輸出lulu喜歡的數的個數

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

int a,b;
int map[10];
int che(int x)
{
    if(map[x])return 1;
    else return 0;
}
void ma(int x)
{
    int w=x;
    int ans=0;
    while(w)
    {
        w=w/10;
        ans++;
    }

    for(int i=1;i<=ans;i++)
    {
        int c;
        c=x%10;
        map[c]=1;
        x=x/10;
    }
    if(x)map[x]=1;

}
int q(int x)
{
    if(x%a==0||x%b==0)return 0;
    int w=x;
    int ans=0;
    while(w)
    {
        w=w/10;
        ans++;
    }

    for(int i=1;i<=ans;i++)
    {
        int c;
        c=x%10;
        if(che(c))return 0;
        x=x/10;
    }
    if(che(x)&&x)return 0;

    return 1;

}
int main()
{
    int t;
    cin>>t;
    for(int i=1;i<=t;i++)
    {
        memset(map,0,sizeof(map));

        cin>>a>>b;
        ma(a);
        ma(b);
        int sum=0;
        for(int i=1;i<=1000;i++)
        {
            if(q(i))sum++;
        }
        cout<<sum<<endl;
    }

    return 0;
}