题解:P12610 [CCC 2025 Junior] Donut Shop
xiaowenxu_qwq · · 题解
题目意思
给定一个 +(加号)或 -(减号),第二行为正整数
思路
在每组数据中,如果第一行字符为 + 则 - 则
代码。
#include<bits/stdc++.h>
#define int __int128
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
//#define getchar() getchar_unlocked()
using namespace std;
inline int read(){
int x=0,f=1;char c=getchar();
while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+c-'0',c=getchar();
return x*f;
}//快读
void write(int x)
{
if(x<0)putchar('-'),x=-x;
if(x<10)putchar(x+'0');
else write(x/10),putchar(x%10+'0');
}//快输
signed main()
{
int D=read();
int E=read();
for(int i=1;i<=E;i++){
if(getchar()=='+')D+=read();
else D-=read();
}
write(D);
return 0;
}