Gym - 100796L Emoticons 水题 字符串处理

2015-2016 ACM ICPC Baltic Selection Contest

L. Emoticons
time limit per test:1 second
memory limit per test:256 megabytes

Bob 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!

Input

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 ")".

Output

In a single line, output either "HAPPY", "BORED" or "SAD" corresponding to Alice's mood.

Examples

Input
10
:)))))))))
Output
HAPPY
Input
1
:
Output
BORED
Input
8
)::(:():
Output
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;
}



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值