VioletaBabel

2607번: 비슷한 단어 본문

백준/백준-C
2607번: 비슷한 단어
Beabletoet 2017. 5. 16. 00:01

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

int main()

{

int n, count = 0, firstLen, secondLen, wordCount = 0;

scanf("%d", &n);

char firstWord[11], secondWord[11], secondCopy[11];

scanf("%s", &firstWord);

firstLen = strlen(firstWord);

for (int i = 1; i < n; ++i, wordCount = 0)

{

scanf("%s", &secondWord);

secondLen = strlen(secondWord);

memcpy(secondCopy, secondWord, sizeof(char) * 11);

for (int j = 0; j < firstLen; ++j)

for (int k = 0; k < secondLen; ++k)

if (firstWord[j] == secondCopy[k])

{

++wordCount;

secondCopy[k] = ' ';

break;

}

if (firstLen == secondLen)

count = (wordCount >= firstLen - 1 && wordCount <= firstLen + 1) ? ++count : count;

else if (firstLen - 1 == secondLen)

count = (wordCount == secondLen) ? ++count : count;

else if (firstLen + 1 == secondLen)

count = (wordCount == firstLen) ? ++count : count;

}

printf("%d", count);

}

'백준 > 백준-C' 카테고리의 다른 글

14582번: 오늘도 졌다  (0) 2017.05.20
1075번: 나누기  (0) 2017.05.20
9426번: 중앙값 측정 (실패)  (0) 2017.05.15
2839번: 설탕 배달  (0) 2017.05.14
14579번: 덧셈과 곱셈  (0) 2017.05.14
Comments