链接: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喜欢的数的个数
示例1
输入
3
2 3
14 23
1234 5678
输出
171
190
7
说明
a=1234 b=5678的时候,只考虑含有数字9,0的数,只有7个,分别是9,99,999,90,990,909,900
备注:
对于100%的数据,
0 < T <= 20;
0 <= a <= 99999;
0 <= b <= 99999。
题解:一个水题,需要注意一下1000以内的数是不是a和b的倍数
#include<stdio.h>
#include <cstring>
int main()
{
int t;
int T[10];
scanf("%d",&t);
while(t --)
{
char a[50],b[50];
memset(T,0,sizeof(T));
scanf("%s%s",a,b);
int cnt=0;
int num1=0,num2=0;
for(int c = 0; c < strlen(a); c ++)
T[a[c]-48]=1;
for(int c = 0; c < strlen(b); c ++)
T[b[c]-48]=1;
for(int c = 0; c < strlen(a); c ++)
num1=num1*10+a[c]-48;
for(int c = 0; c < strlen(b); c ++)
num2=num2*10+b[c]-48;
for(int c = 1; c <= 1000; c ++)
{
if(c%num1==0||c%num2==0)
continue;
int flag=0;
int x=c;
while(x)
{
if(T[x%10]==1)
{
flag=1;
break;
}
x/=10;
}
if(!flag)
cnt++;
}
printf("%d\n",cnt);
}
return 0;
}