题解:P15358 「WYZOI R2」红包
luyunqing123 · · 题解
十分简单的一道题。
本题的核心是只统计小Q(名字为"Q")的收支记录,其他人物的记录无需处理。只需遍历所有记录,判断名字是否为"Q",若是则累加其金额,最终得到小Q的总收益。
那代码如下。
#include<bits/stdc++.h>
using namespace std;
int main(){
long long T,ans=0;
cin>>T;
while(T--){
char s[11];//名字
long long x;//收入或支出
cin>>s>>x;
if(strcmp(s,"Q")==0){//判断人物是不是小Q
ans+=x;//加钱或减钱
}
}
cout<<ans;
return 0;
}