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 29 30 31 32 33 34 35 36 37 38 39 40 41 | #include <stdio.h> #include <string> #include <iostream> using namespace std; int main() { // 입력받는 문장, 웃음, 슬픔 이모티콘 초기화 string line, face; getline(cin, line); face = ":- "; //검색 시작 int len = line.size(); int idx = 0, tmpSmile = 0, tmpSad = 0; for (int i = 0; i < len; i++) { if (line[i] == face[idx]) { idx++; if (idx == 2) { if (line[i + 1] == ')') tmpSmile++; else if (line[i + 1] == '(') tmpSad++; idx = 0; } } else { idx = 0; } } if (tmpSmile > tmpSad) printf("happy"); else if (tmpSmile < tmpSad) printf("sad"); else if (tmpSmile == 0 && tmpSad == 0) printf("none"); else if (tmpSmile == tmpSad) printf("unsure"); } | cs |
'알고리즘 > KMP' 카테고리의 다른 글
5525 IOIOI 백준 (0) | 2019.03.31 |
---|---|
1786 찾기 백준 (0) | 2019.03.29 |