102871: [AtCoder]ABC287 B - Postal Card

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:2 Solved:0

Description

Score : $200$ points

Problem Statement

You are given $N$ strings of length six each, consisting of digits. Let $S_i$ be the $i$-th $(i = 1, 2, \dots, N)$ of them.

You are also given $M$ strings of length three each, consisting of digits. Let $T_j$ be the $j$-th $(j = 1, 2, \dots, M)$ of them.

Find the number of strings among $S_1, S_2, \dots, S_N$ whose last three characters coincide with one or more of $T_1, T_2, \dots, T_M$.

Constraints

  • $1 \leq N, M \leq 1000$
  • $N$ and $M$ are integers.
  • $S_i$ is a string of length $6$ consisting of digits, for all $i = 1, 2, \dots, N$.
  • $T_j$ is a string of length $3$ consisting of digits, for all $j = 1, 2, \dots, M$.

Input

The input is given from Standard Input in the following format:

$N$ $M$
$S_1$
$S_2$
$\vdots$
$S_N$
$T_1$
$T_2$
$\vdots$
$T_M$

Output

Print the answer.


Sample Input 1

3 3
142857
004159
071028
159
287
857

Sample Output 1

2

The last three characters of $S_1$ are 857, which coincide with $T_3$.
The last three characters of $S_2$ are 159, which coincide with $T_1$.
The last three characters of $S_3$ are 028, which do not coincide with $T_1$, $T_2$, or $T_3$.

Thus, the answer is $2$.


Sample Input 2

5 4
235983
109467
823476
592801
000333
333
108
467
983

Sample Output 2

3

Sample Input 3

4 4
000000
123456
987111
000000
000
111
999
111

Sample Output 3

3

Input

题意翻译

给定 $n$ 个数字串和 $m$ 个长度为 $3$ 的数字串,对于每一个数字串,求它的后三位是否在 $m$ 个串中出现过,统计出现过的数字串个数。

Output

分数:$200$分

问题描述

给你$N$个长度为六的由数字组成的字符串。设第$i$个字符串($i=1,2,\dots,N$)为$S_i$。

给你$M$个长度为三的由数字组成的字符串。设第$j$个字符串($j=1,2,\dots,M$)为$T_j$。

找出$S_1, S_2, \dots, S_N$中最后三个字符与$T_1, T_2, \dots, T_M$中的一个或多个相匹配的字符串的数量。

限制条件

  • $1 \leq N, M \leq 1000$
  • $N$和$M$是整数。
  • 对于所有的$i=1,2,\dots,N$,$S_i$是一个长度为$6$的由数字组成的字符串。
  • 对于所有的$j=1,2,\dots,M$,$T_j$是一个长度为$3$的由数字组成的字符串。

输入

输入通过标准输入给出,格式如下:

$N$ $M$
$S_1$
$S_2$
$\vdots$
$S_N$
$T_1$
$T_2$
$\vdots$
$T_M$

输出

打印答案。


样例输入1

3 3
142857
004159
071028
159
287
857

样例输出1

2

$S_1$的最后三个字符是857,与$T_3$相匹配。
$S_2$的最后三个字符是159,与$T_1$相匹配。
$S_3$的最后三个字符是028,不与$T_1$、$T_2$或$T_3$相匹配。

因此,答案是$2$。


样例输入2

5 4
235983
109467
823476
592801
000333
333
108
467
983

样例输出2

3

样例输入3

4 4
000000
123456
987111
000000
000
111
999
111

样例输出3

3

加入题单

上一题 下一题 算法标签: