본문 바로가기

알고리즘 · 코딩

[백준 10769번] 행복한지 슬픈지

문제 링크

www.acmicpc.net/problem/10769

 

10769번: 행복한지 슬픈지

승엽이는 자신의 감정을 표현하기 위해서 종종 문자 메시지에 이모티콘을 넣어 보내곤 한다. 승엽이가 보내는 이모티콘은 세 개의 문자가 붙어있는 구조로 이루어져 있으며, 행복한 얼굴을 나

www.acmicpc.net


C++ 풀이

#include <iostream>
#include <string>
using namespace std;

int main() {
	string sentence;
	getline(cin, sentence);
	string happy = ":-)", sad = ":-(", temp;
	int happyN = 0, sadN = 0;
	for (int i = 0; i < sentence.length() - 2; i++) {
		temp = sentence.substr(i, 3);
		if (temp == happy)
			happyN++;
		else if (temp == sad)
			sadN++;
	}
	if (happyN == 0 && sadN == 0)
		cout << "none";
	else if (happyN == sadN)
		cout << "unsure";
	else if (happyN > sadN)
		cout << "happy";
	else
		cout << "sad";
	return 0;
}

 

 

 

LIST