跳到正文

题解

题解:P12610 [CCC 2025 Junior] Donut Shop

用户 1611410约 1 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 1 分钟
题目
P12610

版本

  1. v1当前

题解

这题看上去很难,实际很简单,我们只需要判断输入的字符是加是减,是加 n 就加 x ,是减 n 就减 x ,最后输出 n 即可。

代码

C++
#include <bits/stdc++.h> //万能头
using namespace std;
#define int long long

int n, x, ans; //定义变量
char c; //定义变量

signed main()
{
 	ios::sync_with_stdio(false);
 	cin.tie(0), cout.tie(0);
 	cin >> ans; //输入ans
 	cin >> n; //输入组数
 	for (int i = 1; i <= n; i++) //循环读入c, x
 	{
 		cin >> c >> x; //输入
 		if (c == '+') ans += x; //如果加就加
 		if (c == '-') ans -= x; //如果减就减
	}
	cout << ans; // 输出答案
	return 0; //完美AC
}
原文