- getline(cin, str)
- idx = 0, cnt_happy = 0
- while true:
- if str.find(":-)", idx) == string::npos: break
- else:
- idx = str.find(":-)", idx) + 1
- cnt_happy += 1
- idx = 0, cnt_sad = 0
- while true:
- if str.find(":-(", idx) == string::npos: break
- else:
- idx = str.find(":-(", idx) + 1
- cnt_sad += 1
- if cnt_happy==0 && cnt_sad==0: none
- else if cnt_happy == cnt_sad: unsure
- else if cnt_happy > cnt_sad: happy
- else: sad
#include <iostream>
#include <string>
int main()
{
std::string str;
std::getline(std::cin, str);
int idx = 0, cnt_happy = 0;
while (true) {
if (str.find(":-)", idx) == std::string::npos) break;
idx = str.find(":-)", idx) + 1;
cnt_happy++;
}
idx = 0;
int cnt_sad = 0;
while (true) {
if (str.find(":-(", idx) == std::string::npos) break;
idx = str.find(":-(", idx) + 1;
cnt_sad++;
}
if (cnt_happy == 0 && cnt_sad == 0) std::cout << "none\n";
else if (cnt_happy == cnt_sad) std::cout << "unsure\n";
else if (cnt_happy > cnt_sad) std::cout << "happy\n";
else std::cout << "sad\n";
}
Leave a comment