본문 바로가기
Algorithm/백준

[C++] 백준 4999번: 아!

by Ruas 2022. 2. 15.
728x90

 

 

4999번: 아!

입력은 두 줄로 이루어져 있다. 첫째 줄은 재환이가 가장 길게 낼 수 있는 "aaah"이다. 둘째 줄은 의사가 듣기를 원하는 "aah"이다. 두 문자열은 모두 a와 h로만 이루어져 있다. a의 개수는 0보다 크거

www.acmicpc.net

 

 

#include <iostream>
#include <string>

using namespace std;

string maximum;
string input;
int maxcnt = 0;
int cnt = 0;

int main() {
	cin >> maximum;
	cin >> input;

	for (int i = 0; i < maximum.length(); i++) {
		if (maximum[i] == 'a') {
			maxcnt++;
		}
		else {
			break;
		}
	}

	for (int i = 0; i < input.length(); i++) {
		if (input[i] == 'a') {
			cnt++;
		}
		else {
			break;
		}
	}

	if (maxcnt < cnt) {
		cout << "no" << "\n";
	}
	else if (maxcnt >= cnt) {
		cout << "go" << "\n";
	}

	return 0;
}
728x90

댓글