Sorry, your browser cannot access this site
This page requires browser support (enable) JavaScript
Learn more >

题目描述

image-20250325185847974

思路

对于每一行命令检测+是否在里面就好。

代码

Python

1
2
3
4
5
6
7
8
9
n = int(input())
x=0
for _ in range(n):
op = input()
if "+" in op:
x += 1
else:
x -= 1
print(x)

C

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <stdio.h>
#include <string.h>

int main() {
int n, x = 0;
scanf("%d", &n);
char op[5];

for (int i = 0; i < n; i++) {
scanf("%s", op);
if (strchr(op, '+')) {
x += 1;
} else {
x -= 1;
}
}
printf("%d\n", x);
return 0;
}

C++