[BOJ 13456] Richard Hamming

View as PDF

Submit solution

Points: 1
Time limit: 1.0s
Memory limit: 256M

Problem type
Allowed languages
Assembly, Awk, C, C++, Java, Pascal, Perl, Python, Sed, Text

The Hamming distance dH( ⃗v, ⃗u) between two n-dimensional vectors ⃗v = (v1, . . . , vn) and ⃗u =(u1, . . . , un) is defined as dH( ⃗v, ⃗u) = |{i : vi ≠ ui and i ∈ {1, . . . , n}}|, i.e., the number of positions at which the corresponding entries are different. For example, the Hamming distance between (1, 2, 3, 4, 5) and (1, 0, 0, 4, 5) is 2, since these two vectors differ only at the second and the third positions. Please write a program to compute the Hamming distance between two n-dimensional vectors.

입력 형식

On the first line there is a single integer T (T ≤ 100) indicating the number of test cases. Each test case consists of three lines. The first line of each test case contains an integer n (0 < n ≤ 50) indicating the dimension of the vectors. The second line contains n integers v1, . . . , vn, and the third line contains n integers u1, . . . , un. You may assume that v1, . . . , vn, u1, . . . , un ∈ {0, 1, . . . , 99}.

출력 형식

For each test case, output the Hamming distance between (v1, . . . , vn) and (u1, . . . , un).

예제 입력

2
3
1 2 3
3 2 1
4
1 0 1 0
1 0 1 1

예제 출력

2
1

Comments

There are no comments at the moment.