2015-2016 ACM ICPC Baltic Selection Contest
L. EmoticonsBob has received a text message from his girlfriend Alice. The message consists only of colons (":") and brackets ("(" and ")"). Two consecutive characters in the message form an emoticon if one of them is a colon and the other one is a bracket. If the bracket's inner side faces the colon, the emoticon is a smiley; otherwise it is a frowney. So, ":)" and "(:" are smilies, and ":(" and "):" are frownies. One character can belong to two emoticons: for example, there are both a smiley and a frowney in the message "):)".
Unfortunately, Bob has trouble understanding the message. He can only find out Alice's mood based on the number of emoticons in the message:
- If there are more smilies than frownies, Alice is happy.
- If the number of smilies is equal to the number of frownies, Alice is just texting him because she's bored.
- If there are more frownies than smilies, Alice is sad.
Help Bob determine how does Alice feel!
The first line contains a single integer n, the length of the message (1 ≤ n ≤ 105). The next line contains the message, a string consisting of n characters. Each of the characters is either ":", "(" or ")".
In a single line, output either "HAPPY", "BORED" or "SAD" corresponding to Alice's mood.
10 :)))))))))
HAPPY
1 :
BORED
8 )::(:():
SAD
题目给出一行字符串,由“:”,“(”和“)”组成,其中“(:”和“:)”为笑脸,“):”和“:(”为哭脸,问在给出的一行字符串中,笑脸和哭脸哪个多。笑脸多输出“HAPPY”,哭脸多输出“SAD”,一样多就输出“BORED”,直接输入字符串进去跑循环即可,没什么好说的。
下面AC代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char s[100005];
int main()
{
int n;
int i;
int t;
int ha,sa;
while(scanf("%d",&n)!=EOF)
{
t=0;
ha=0;
sa=0;
scanf("%s",s);
for(i=0;i<n;i++)
{
if(s[i]==':')
{
if(i!=0)
{
if(s[i-1]==')')
sa++;
else if(s[i-1]=='(')
ha++;
}
if(i!=n-1)
{
if(s[i+1]==')')
ha++;
else if(s[i+1]=='(')
sa++;
}
}
}
t=ha-sa;
if(t==0)
cout<<"BORED"<<endl;
else if(t>0)
cout<<"HAPPY"<<endl;
else if(t<0)
cout<<"SAD"<<endl;
}
return 0;
}