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/

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-03 18:13
点赞 评论 收藏
分享
ohs的小木屋:比不少实习待遇高了
点赞 评论 收藏
分享
06-26 22:20
门头沟学院 Java
码农索隆:让你把简历发给她,她说一些套话,然后让你加一个人,说这个人给你改简历,然后开始卖课
我的求职精神状态
点赞 评论 收藏
分享
06-13 17:33
门头沟学院 Java
顺序不记了,大致顺序是这样的,有的相同知识点写分开了1.基本数据类型2.基本数据类型和包装类型的区别3.==和equals区别4.ArrayList与LinkedList区别5.hashmap底层原理,put操作时会发生什么6.说出几种树型数据结构7.B树和B+树区别8.jvm加载类机制9.线程池核心参数10.创建线程池的几种方式11.callable与runnable区别12.线程池怎么回收线程13.redis三剑客14.布隆过滤器原理,不要背八股,说说真正使用时遇到了问题没有(我说没有,不知道该怎么回答了)15.堆的内存结构16.自己在写项目时有没有遇见过oom,如何处理,不要背八股,根据真实经验,我说不会17.redis死锁怎么办,watchdog机制如何发现是否锁过期18.如何避免redis红锁19.一个表性别与年龄如何加索引20.自己的项目的QPS怎么测的,有没有真正遇到大数量表21.说一说泛型22.springboot自动装配原理23.springmvc与springboot区别24.aop使用过嘛?动态代理与静态代理区别25.spring循环依赖怎么解决26.你说用过es,es如何分片,怎么存的数据,1000万条数据怎么写入库中27.你说用limit,那么在数据量大之后,如何优化28.rabbitmq如何批次发送,批量读取,答了延迟队列和线程池,都不对29.计网知不知道smtp协议,不知道写了对不对,完全听懵了30.springcloud知道嘛?只是了解反问1.做什么的?短信服务,信息量能到千万级2.对我的建议,基础不错,但是不要只背八股,多去实际开发中理解。面试官人不错,虽然没露脸,但是中间会引导我回答问题,不会的也只是说对我要求没那么高。面完问我在济宁生活有没有困难,最快什么时候到,让人事给我聊薪资了。下午人事打电话,问我27届的会不会跑路,还在想办法如何使我不跑路,不想扣我薪资等。之后我再联系吧,还挺想去的😭,我真不跑路哥😢附一张河科大幽默大专图,科大就是大专罢了
查看30道真题和解析
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务