[BOJ] 2607 비슷한 단어

Time Lapse :NONE

2607.c

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <stdio.h>
#include <string.h>
#include <math.h>
char I[100][26],l[100],b[11],N,a,i,j,d,f;
main() {
scanf("%d",&N);
for (i = 0; i < N; ++i) {
scanf("%s", b);
l[i] = strlen(b);
for (j = 0; j < l[i]; ++j)
++I[i][b[j]-'A'];
}
for (j = 1; j < N; ++j) {
if (abs(l[0] - l[j]) >= 2) continue;
d = f = 0;
for (i = 0; i < 26; ++i) {
d += abs(I[0][i]-I[j][i]);
if(I[0][i]!=I[j][i])++f;
}
if(d<=2&&f<=2)++a;
}
printf("%d", a);
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/07/30/PS/BOJ/2607/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.