迷之好奇
Time Limit: 2000 ms Memory Limit: 65536 KiB
Problem Description
FF得到了一个有n个数字的集合。不要问我为什么,有钱,任性。
FF很好奇的想知道,对于数字x,集合中有多少个数字可以在x前面添加任意数字得到。
如,x = 123,则在x前面添加数字可以得到4123,5123等。
Input
多组输入。
对于每组数据
首先输入n(1<= n <= 100000)。
接下来n行。每行一个数字y(1 <= y <= 100000)代表集合中的元素。
接下来一行输入m(1 <= m <= 100000),代表有m次询问。
接下来的m行。
每行一个正整数x(1 <= x <= 100000)。
Output
对于每组数据,输出一个数字代表答案。
Sample Input
3 12345 66666 12356 3 45 12345 356
Sample Output
1 0 1
当一个整数中间存在0时,一些后缀就重复记录了。。比如说,10086这个数,我们让它对10,100,1000,10000取余结果为6,86,86,86 这样以来86这个后缀被记录了3次,但结果应为1次,所以我们在取余的时候,要判断一下余数是否比用来取余的数/10后 大 ,如果大于它,则计数一次,反之直接跳过,详见代码
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main(void)
{
int n;
int x;
int a[100001];
int s;
int y;
while(~scanf("%d", &n))
{
memset(a, 0, sizeof(a));
for(int i = 0; i < n; i++)
{
scanf("%d", &x);
s = 10;
while(1)
{
if(x % s == x)
{
break;
}
int t = x % s;
if(t >= s / 10)
{
a[t]++;
}
s *= 10;
}
}
int m;
scanf("%d", &m);
for(int i = 0; i < m; i++)
{
scanf("%d", &y);
printf("%d\n", a[y]);
}
}
return 0;
}