티스토리 뷰

PS/백준

2941번 크로아티아 알파벳

unside 2019. 6. 22. 17:13

백준 2941번

문제 사이트 :
https://www.acmicpc.net/problem/2941

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>

using namespace std;

int main(void) {
	char ch[101];
	int num = 0;

	scanf("%s", &ch);
	for (int i = 0; ch[i] != '\0';) {
		if (ch[i] == 'c') {
			if (ch[i + 1] == '=') {
				i += 2;
				num++;
			}
			else if (ch[i + 1] == '-') {
				i += 2;
				num++;
			}
			else {
				i++;
				num++;
			}
		}
		else if (ch[i] == 'd') {
			if (ch[i + 1] == '-') {
				i += 2;
				num++;
			}
			else if(ch[i+1] == 'z'){//d다음 z가 오는경우 1.다음 알파벳 z인경우 2. 크로아티아 알파벳인경우
				if (ch[i + 2] == '=') { //크로아티아 알파벳
					i += 3;
					num++;
				}
				else { //일반 알파벳
					i++;
					num++;
				}
			}
			else {
				i++;
				num++;
			}
		}
		else if (ch[i] == 'l') {
			if (ch[i + 1] == 'j') {
				i += 2;
				num++;
			}
			else {
				i++;
				num++;
			}
		}
		else if (ch[i] == 'n') {
			if (ch[i + 1] == 'j') {
				i += 2;
				num++;
			}
			else {
				i++;
				num++;
			}
		}
		else if (ch[i] == 's') {
			if (ch[i + 1] == '=') {
				i += 2;
				num++;
			}
			else {
				i++;
				num++;
			}
		}
		else if (ch[i] == 'z') {
			if (ch[i + 1] == '=') {
				i += 2;
				num++;
			}
			else {
				i++;
				num++;
			}
		}
		else {
			i++;
			num++;
		}
	}
	printf("%d", num);
	return 0;
}

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

4673번 셀프 넘버  (0) 2019.06.24
4344번 평균은 넘겠지  (0) 2019.06.22
2920번 음계  (0) 2019.06.22
2908번 상수  (0) 2019.06.22
2675번 문자열 반복  (0) 2019.06.22
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/02   »
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
글 보관함