282A. Bit++

282A. Bit++

282A. Bit++

  • time limit per test1 second
  • memory limit per test256 megabytes
  • inputstandard input
  • outputstandard output

The classic programming language of Bitland is Bit++. This language is so peculiar and complicated.

Bitland的经典编程语言是Bit++。这种语言是如此奇特和复杂。

The language is that peculiar as it has exactly one variable, called x. Also, there are two operations:

这种语言非常独特,因为它只有一个变量,叫做x。此外,有两种操作:

  • Operation ++ increases the value of variable x by 1.

Operation++将变量x的值增加1。

  • Operation -- decreases the value of variable x by 1.

操作--将变量x的值减少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.

Bit++语言中的语句是一个序列,只包含一个操作和一个变量x。该语句不带空格,即只能包含字符“+”、“-”、“x”。执行语句意味着应用它包含的操作。

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.

Bit++中的程序是一系列语句,每个语句都需要执行。执行一个程序意味着执行它包含的所有语句。

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

你得到了一个用Bit++语言编写的程序。x的初始值为0。执行该程序并找到其最终值(执行该程序时变量的值)。

Input

The first line contains a single integer n (1 ≤ n ≤ 150) — the number of statements in the programme.

第一行包含一个整数n(1 ≤ n ≤ 150)-节目中的发言次数。

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.

接下来的n行分别包含一条语句。每个语句只包含一个运算(++或--)和一个变量x(表示为字母«x»)。因此,不存在空语句。操作和变量可以按任意顺序写入。

Output

Print a single integer — the final value of x.

打印一个整数——x的最终值。

Examples
input1

1

++X

output1

1

input2

2

X++

--X

output2

0

Solution

考虑到X++或者++X在第二位上都是+,X--或者--X在第二位上都是-,因此只要对第二位进行判断为+还是-即可

Code
#include <iostream>
using namespace std;

//282A. Bit++
int main() {
    int n = 0;//n:发言次数
    cin >> n;
    int x =0;//x:x的最终值
    for(int i = 0;i < n;i++){
        string str;
        cin >> str;
        if(str[1]=='+'){
            x++;
        }else{
            x--;
        }
    }
    cout << x << endl;
    return 0;
}
CodeForces 文章被收录于专栏

https://codeforces.ml/

全部评论

相关推荐

NBA球星伦纳德:jd是这样的,工作连拧螺丝都算不上
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
正在热议
更多
# 春招至今,你的战绩如何? #
11066次浏览 94人参与
# 你的实习产出是真实的还是包装的? #
1956次浏览 42人参与
# MiniMax求职进展汇总 #
24117次浏览 309人参与
# 军工所铁饭碗 vs 互联网高薪资,你会选谁 #
7640次浏览 43人参与
# 简历第一个项目做什么 #
31744次浏览 341人参与
# 重来一次,我还会选择这个专业吗 #
433544次浏览 3926人参与
# 米连集团26产品管培生项目 #
6035次浏览 216人参与
# 当下环境,你会继续卷互联网,还是看其他行业机会 #
187205次浏览 1122人参与
# 牛客AI文生图 #
21446次浏览 238人参与
# 不考虑薪资和职业,你最想做什么工作呢? #
152446次浏览 888人参与
# 研究所笔面经互助 #
118964次浏览 577人参与
# 简历中的项目经历要怎么写? #
310361次浏览 4219人参与
# AI时代,哪些岗位最容易被淘汰 #
63815次浏览 828人参与
# 面试紧张时你会有什么表现? #
30510次浏览 188人参与
# 你今年的平均薪资是多少? #
213134次浏览 1039人参与
# 你怎么看待AI面试 #
180131次浏览 1258人参与
# 高学历就一定能找到好工作吗? #
64331次浏览 620人参与
# 你最满意的offer薪资是哪家公司? #
76539次浏览 374人参与
# 我的求职精神状态 #
448131次浏览 3129人参与
# 正在春招的你,也参与了去年秋招吗? #
363512次浏览 2638人参与
# 腾讯音乐求职进展汇总 #
160674次浏览 1112人参与
# 校招笔试 #
471179次浏览 2964人参与
牛客网
牛客网在线编程
牛客网题解
牛客企业服务