CodeFoeces-686A

题目

原题链接:A. Free Ice Cream

题意

最开始有m个冰淇淋,每次输入一个+/-和数字,+代表进货,-代表送出,若送出的数量大于持有数量,则计数器+1。问最后有多少冰淇淋和计数器。

代码

#include
using namespace std;
int main() {
    int n,c=0;
    long long sum,t;
    char s;
    scanf("%d%lld",&n,&sum);
    while(n--) {
        getchar();
        scanf("%c %lld",&s,&t);
        if(s=='-') {
            if(t>sum) {
                c++;
            } else {
                sum-=t;
            }
        } else {
            sum+=t;
        }
    }
    printf("%lld %d\n",sum,c);
    return 0;
}

你可能感兴趣的:(CodeFoeces-686A)