B - Bit++
Problem description
The classic programming language of Bitland is Bit++. This language is so peculiar and complicated.
The language is that peculiar as it has exactly one variable, called x. Also, there are two operations:
- Operation ++ increases the value of variable x by 1.
- Operation -- decreases the value of variable x by 1.
A statement in language Bit++ is a sequence, consisting of exactly one operation and one variable x. The statement is written without spaces, that is, it can only contain characters "+", "-", "X". Executing a statement means applying the operation it contains.
A programme in Bit++ is a sequence of statements, each of them needs to be executed. Executing a programme means executing all the statements it contains.
You're given a programme in language Bit++. The initial value of x is 0. Execute the programme and find its final value (the value of the variable when this programme is executed).
Input
The first line contains a single integer n (1 ≤ n ≤ 150) — the number of statements in the programme.
Next n lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable x (denoted as letter «X»). Thus, there are no empty statements. The operation and the variable can be written in any order.
Output
Print a single integer — the final value of x.
Examples
Input
1
++X
Output
1
Input
2
X++
--X
Output
0
解题思路:给X初始值为0,通过n个操作,实现加1减1运算,水过!
AC代码:
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,x=;char q[];
cin>>n;
while(n--){
cin>>q;
if(q[]=='+'||q[]=='+')x++;
else x--;
}
cout<<x<<endl;
return ;
}
随机推荐
- iptables详解(4):iptables匹配条件总结之一
所属分类:IPtables Linux基础 在本博客中,从理论到实践,系统的介绍了iptables,如果你想要从头开始了解iptables,可以查看iptables文章列表,直达链接如下 iptab ...
- 安装低版本django1.11出错
错误信息: File "C:\python3\lib\site-packages\django\utils\autoreload.py", line 227, in wrapper ...
- Python 递归、匿名函数、map和filter day4
一.递归---函数自己调用自己 1.一个错误递归的例子: count=0 def hello(): global count count+=1 print("count %s"%c ...
- bootstrap中chosen控件样式有时会冲突
加上这句话试试 $(".chosen-container").css("width","100%"); 或者 100%改成 100px试试
- Django - 日志工作中常用配置
工作中常用配置 # 日志配置 BASE_LOG_DIR = os.path.join(BASE_DIR, "log") LOGGING = { 'version': 1, # 保留 ...
- fastclick:处理移动端click事件300毫秒延迟
fastclick:处理移动端click事件300毫秒延迟 1.兼容性 iOS 3及更高版本的移动Safari iOS 5及更高版本的Chrome Android上的Chrome(ICS) Opera ...
- echarts demo
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- sha2 替换sha1 时间表
由于sha1签名算法进入淘汰阶段,逐渐弃用中,sha1升级为sha2是大势所趋. 微软已经正式发布sha1弃用策略: http://blogs.technet.com/b/pki/archive/20 ...
- PatentTips - Mechanisms for strong atomicity in a transactional memory system
BACKGROUND Advances in semi-conductor processing and logic design have permitted an increase in the ...
- html简单实现下拉菜单
主要用到的知识ul和li标签 ul li 是一个组合:是无序列表标签,在实际中用的非常多,与之对应的是有序列表:ol lili是不能单独使用,必须在于ul之中的ul是块级元素,能直接定义宽高,而li是 ...