
#include <stdio.h>
#include <string.h>
int main() {
char word[101];
scanf("%s", word);
int count = 0;
int length = strlen(word);
for (int i = 0; i < length; i++) {
// 'dz=' 확인
if (word[i] == 'd' && word[i + 1] == 'z' && word[i + 2] == '=') {
count++;
i += 2; // 'dz='는 세 글자가 알파벳 하나이므로 2칸 건너뜀
}
// 나머지 확인
else if ((word[i] == 'c' && (word[i + 1] == '=' || word[i + 1] == '-')) ||
(word[i] == 'd' && word[i + 1] == '-') ||
(word[i] == 'l' && word[i + 1] == 'j') ||
(word[i] == 'n' && word[i + 1] == 'j') ||
(word[i] == 's' && word[i + 1] == '=') ||
(word[i] == 'z' && word[i + 1] == '=')) {
count++;
i++; // 이 경우는 두 글자가 알파벳 하나이므로 1칸 건너뜀
}
// 일반 알파벳
else {
count++;
}
}
printf("%d\n", count);
return 0;
}
풀이:
문자열을 처음부터 끝까지 탐색하며 크로아티아 알파벳을 찾는다
'z=: d, z, = 이 세 글자가 연속으로 나오는 경우를 체크
이 경우 세 글자가 하나의 알파벳이므로 i를 2칸 건너뛴다
다른 크로아티아 알파벳: 그 외에 두 글자로 이루어진 크로아티아 알파벳은 i를 1칸 건너뛴다
일반 알파벳: 그대로 1개로 셈
크로아티아 알파벳의 개수를 출력

#include <stdio.h>
#include <string.h>
int main() {
int N;
scanf("%d", &N);
char names[20][13]; // 최대 20개의 이름, 각 이름은 최대 12자
for (int i = 0; i < N; i++) {
scanf("%s", names[i]);
}
int increasing = 1, decreasing = 1;
for (int i = 1; i < N; i++) {
if (strcmp(names[i - 1], names[i]) < 0) {
decreasing = 0;
} else if (strcmp(names[i - 1], names[i]) > 0) {
increasing = 0;
}
}
if (increasing) {
printf("INCREASING\n");
} else if (decreasing) {
printf("DECREASING\n");
} else {
printf("NEITHER\n");
}
return 0;
}
풀이
increasing 변수와 decreasing 변수를 각각 1로 초기화하여 이름들이 증가하는 순서인지 감소하는 순서인지 확인
strcmp() 함수로 두 문자열을 비교
만약 이전 이름이 현재 이름보다 작으면(strcmp 결과가 0보다 작으면) 증가하는 순서
decreasing도 동일하게 적용
increasing이 1이면 "INCREASING", decreasing이 1이면 "DECREASING"을 출력
둘 다 해당하지 않으면 "NEITHER" 출력