Image (Codeforces 1721A)
Tags: Greedy, implementation

You have an image file of size $$$2 \times 2$$$, consisting of $$$4$$$ pixels. Each pixel can have one of $$$26$$$ different colors, denoted by lowercase Latin letters.You want to recolor some of the pixels of the image so that all $$$4$$$ pixels have the same color. In one move, you can choose no more than two pixels of the same color and paint them into some other color (if you choose two pixels, both should be painted into the same color).What is the minimum number of moves you have to make in order to fulfill your goal?

Input: The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases.Each test case consists of two lines. Each of these lines contains two lowercase letters of Latin alphabet without any separators, denoting a row of pixels in the image.

Output: For each test case, print one integer — the minimum number of moves you have to make so that all $$$4$$$ pixels of the image have the same color.

Note: Let's analyze the test cases of the example.In the first test case, you can paint the bottom left pixel and the top right pixel (which share the same color) into the color r, so all pixels have this color.In the second test case, two moves are enough:  paint both top pixels, which have the same color c, into the color b;  paint the bottom left pixel into the color b. In the third test case, all pixels already have the same color.In the fourth test case, you may leave any of the pixels unchanged, and paint all three other pixels into the color of that pixel in three moves.In the fifth test case, you can paint both top pixels into the color x.

Sample Inputs:
5
rb
br
cc
wb
aa
aa
ab
cd
yy
xx

Sample Outputs:
1
2
0
3
1

Solution (Python):
casos = int(input())
movimientos = []
for i in range(0, casos):
    fila_1 = list(input())
    fila_2 = list(input())
    lista = fila_1 + fila_2
    letras_distintas = len(set(lista))
    if letras_distintas == 1:
        movimientos.append(0)
    if letras_distintas == 2:
        movimientos.append(1)
    if letras_distintas == 3:
        movimientos.append(2)
    if letras_distintas == 4:
        movimientos.append(3)
for i in range(0, len(movimientos)):
    print(movimientos[i])

Solution (Python):
t = int(input())
for i in range(t):
    linea1 = input()
    linea2 = input()
    lista = [linea1[0], linea1[1], linea2[0], linea2[1]]
    lista2 = []
    for e in lista:
        if e not in lista2:
            lista2.append(e)
    if len(lista2) == 4:
        print(3)
    elif len(lista2) == 3:
        print(2)
    elif len(lista2) == 2:
        print(1)
    else:
        print(0)

Solution (Python):
for _ in range(int(input())):
    a = input()
    b = input()
    l = a + b
    print(len(set(l)) - 1)