C++/백준 C++

[C/C++] 백준 30700번 KOREA 문자열 만들기

CE : 하랑 2023. 11. 22. 13:01

 

 

 

 

 

코드

 

#include <iostream>
#include <string> 

using namespace std;

int main()
{
	string korea = "KOREA";
	string str;
	int count = 0; // korea 인덱스 카운트

	cin >> str;

	for (int i = 0; i < str.size(); i++) {

		if (korea[count%5] == str[i]) { // KOREA 순으로 str에서 순서대로 있는지 확인
			count++; // 있는 경우 인덱스 증가
		}
	}

	cout << count;

	return 0;
}