538. Emoticons

题目连接:

http://acm.sgu.ru/problem.php?contest=0&problem=538

Description

A berland national nanochat Bertalk should always stay up-to-date. That's why emoticons highlighting was decided to be introduced. As making emoticons to be highlighted is not exactly the kind of task one performs everyday but this task had to be done as soon as possible, the following simple rule was decided to be introduced: a round opening or closing bracket be considered part of an emoticon if:

this is an opening bracket and there exists the nearest bracket following to the right. The nearest round bracket to the right should be a closing bracket and there shouldn't be anything between the brackets but spaces and Latin letters,

or else it can be a closing bracket and there exists the nearest round bracket following to the left. The nearest round bracket to the left should be an opening bracket. Besides, there shouldn't be anything between the brackets but spaces and Latin letters.

If a bracket doesn't satisfy the conditions, it is considered a part of an emoticon. For example, let's consider the string "Hi:) (it is me) I have bad news:-((". In the string only the brackets that outline "it is me" aren't emoticons. Note that an opening bracket immediatelly followed by a closing bracket, i.e. "()", are not parts of emoticons by definition.

Your task is to print the number of brackets that are parts of emoticons in the given string.

Input

The input data consist of a single non-empty string. The length of the string does not exceed 105 characters. The string consists of lowercase and uppercase Latin letters, spaces, round brackets and punctuation marks: "-", ":", ",", ";". The string does not begin with and does not end with a space.

Output

Print a single number — the required number of brackets that are part of emoticons.

Sample Input

Hi:) (it is me) I have bad news:-((

Sample Output

3

Hint

题意

两个括号内如果只有英文字母 空格的话,就说明这个是正常的括号

否则就是表情括号

问你表情括号有多少个

题解:

直接暴力扫一遍就好了,水题

代码

#include<bits/stdc++.h>
using namespace std; string s;
int check(char c)
{
if(c=='(')return 1;
if(c==')')return 2;
if(c==' ')return 3;
if(c<='Z'&&c>='A')return 3;
if(c<='z'&&c>='a')return 3;
return 4;
}
int main()
{
getline(cin,s);
int ans = 0;
int flag = 0;
for(int i=0;i<s.size();i++)
{
if(check(s[i])==2)
{
if(flag == 1)
flag = 0;
else
ans += 1;
}
else if(check(s[i])==1)
{
if(flag==1)
ans++;
flag = 1;
}
else if(check(s[i])==3)
continue;
else if(check(s[i])==4)
{
if(flag==1)
ans++;
flag = 0;
}
}
cout<<ans+flag<<endl;
}

最新文章

  1. Nginx + Tomcat Windows下的负载均衡配置
  2. 如何写出优雅的Python(二)
  3. lecture13-BP算法的讨论和置信网
  4. 如何修改SVN已提交项目的message log
  5. Java算法-hash算法
  6. 页面静态化3 --- 伪静态技术之Apache的rewrite机制
  7. web处理jsp文件的三个阶段
  8. C++ 库研究笔记——通过inline避免hpp 的mutiple definition 错误
  9. Flex Builder 4.6切换语言
  10. CSRF原理
  11. c++选择重载函数
  12. JAVA自学笔记12
  13. python编写shell脚本详细讲解
  14. maven 技巧
  15. 第四章: 4.1 logging模块 | 正则表达式
  16. git安装与初始化
  17. Java实现继承过程概述
  18. 8 -- 深入使用Spring -- 4...1 为什么需要AOP
  19. Angular7 Drag and Drop
  20. Delphi7下使用FastMM4

热门文章

  1. Golang几个常用记录日志对比
  2. bzoj 1806 [Ioi2007]Miners 矿工配餐(DP)
  3. ipc.Client: Retrying connect to server: h1/192.168.1.61:9000. Already tried 0 time(s);解决方法
  4. 20151007kaggle Titanic心得
  5. 关于VSS配置遇到的问题及解决方法
  6. POJ 2318 TOYS (计算几何,叉积判断)
  7. Struts Hello World Example
  8. 安装CiscoWorks LMS
  9. JS鼠标滑轮事件的写法和按键的事件
  10. C# 扩展方法奇思妙用高级篇六:WinForm 控件选择器