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 ;
}
随机推荐
- jQuery如何追加tr到table中 添加到头或者尾
jQuery 添加新内容有以下四个方法: append() - 在被选元素的结尾插入内容 prepend() - 在被选元素的开头插入内容 after() - 在被选元素之后插入内容 before() ...
- Bequeath Connection and SYS Logon
The following example illustrates how to use the internal_logon and SYSDBA arguments to specify the ...
- [如何在mac下使用gulp] 2. gulp模块的常用方法
常用的gulp模块方法有: gulp.src() gulp.src('client/one.js'); //指定明确的要处理文件 gulp.src('client/*.js'); //处理client ...
- 洛谷——P1196 [NOI2002]银河英雄传说
P1196 [NOI2002]银河英雄传说 题目大意: 给你一个序列,支持两种操作: 合并指令为$M_{i,j}$j,含义为第i号战舰所在的整个战舰队列,作为一个整体(头在前尾在后)接至第j号战舰所 ...
- JAVA学习总结-基础语法
/** * 这篇文章供自己学习JAVA总结回顾使用 * 主要借鉴了马士兵老师的视频进行总结 * @author Kingram */ 标识符的概念和命名规则 JAVA常量---不可变的变量 程序的执行 ...
- JS练习:表格全选与全不选
代码: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title ...
- dubbo服务telnet命令的使用
转自:https://www.cnblogs.com/feiqihang/p/4387330.html dubbo服务发布之后,我们可以利用telnet命令进行调试.管理.Dubbo2.0.5以上版本 ...
- gap lock/next-key lock浅析Basic-Paxos协议日志同步应用
http://www.cnblogs.com/renolei/p/4673842.html 当InnoDB在判断行锁是否冲突的时候, 除了最基本的IS/IX/S/X锁的冲突判断意外, InnoDB还将 ...
- 阿里2016实习offer五面经验与总结
前言 眼下楼主已经拿到阿里实习offer,一共经历了5次面试,当中4轮技术面.1轮HR面试.在这里分享一下自己的面试经验和学习总结.写这篇面经主要是希望可以帮助很多其它的小伙伴.我本科毕业于中南大学信 ...
- Java 构造时成员初始化的陷阱
1.首先列出代码 Base.java public class Base { Base() { preProcess(); } void preProcess() {} } Derived.java ...