본문 바로가기
알고리즘/문자와 문자열

5218 알파벳 거리

by tryotto 2020. 1. 5.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <stdio.h>
#include <string.h>
 
int dist(int idx, char* a, char* b) {
    int chA = (int)a[idx];
    int chB = (int)b[idx];
 
    if (chA <= chB) {
        return chB - chA;
    }
    else {
        return 26 - (chA - chB);
    }
}
 
int main() {
    int n;
    scanf("%d"&n);
 
    while (n--) {
        char a[105= { 0 }, b[105= { 0 };
        scanf("%s %s"&a, &b);
 
        printf("Distances: ");
 
        int len = strlen(a);
        for (int i = 0; i < len; i++) {
            printf("%d ",dist(i, a, b));
        }
        printf("\n");
    }
}
cs


'알고리즘 > 문자와 문자열' 카테고리의 다른 글

3986 좋은 단어  (0) 2020.01.06
10551 STROJOPIS  (0) 2020.01.06
11656 접미사 배열  (0) 2020.01.05
1371 가장 많은 글자  (0) 2020.01.05
1764 듣보잡  (0) 2020.01.05