Notice
Recent Posts
Recent Comments
Link
안녕 세상아,
[백준/c++] 2941 크로아티아 알파벳 본문
https://www.acmicpc.net/problem/2941
c, d, l, n, s, z 일 때 if절로 분기 나눠서 풀면 된다.
크로아티아 숫ㅈㅏ 만나면 i++로 넘어가고 모든 조건 끝에 무조건 cnt++해주면 쉽게 풀 수 있다.
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
string str;
cin >> str;
int cnt = 0;
for (int i = 0; i < str.size(); i++) {
if (str[i] == 'c') {
if (str[i + 1] == '=' || str[i + 1] == '-') {
i++;
}
}
if (str[i] == 'd') {
if (str[i + 1] == 'z' && str[i + 2] == '=')
i += 2;
if (str[i + 1] == '-')
i++;
}
if (str[i] == 'l') {
if (str[i + 1] == 'j')
i++;
}
if (str[i] == 'n') {
if (str[i + 1] == 'j')
i++;
}
if (str[i] == 's') {
if (str[i + 1] == '=')
i++;
}
if (str[i] == 'z') {
if (str[i + 1] == '=')
i++;
}
cnt++;
}
cout << cnt << '\n';
}'백준' 카테고리의 다른 글
| [백준/c++] 좌표 정렬하기 (1) | 2025.01.01 |
|---|---|
| [백준/c++] 4673 셀프 넘버 (1) | 2024.12.28 |
| [백준/c++] 2751 수 정렬하기 2 (0) | 2024.12.27 |
| [백준/c++] 1316 그룹 단어 체커 (0) | 2024.12.17 |
| [백준/c++] 4963 섬의 개수 (0) | 2024.11.16 |