zoukankan      html  css  js  c++  java
  • CodeForces 686A Free Ice Cream (水题模拟)

    题意:给定初始数量的冰激凌,然后n个操作,如果是“+”,那么数量就会增加,如果是“-”,如果现有的数量大于等于要减的数量,那么就减掉,如果小于,

    那么孩子就会离家。问你最后剩下多少冰激凌,和出走的孩子数量。

    析:多水的一个题,就是一个模拟,如果是+,就加上,如果是‘-’,就判断一下,如果不够,就记录下来。

    代码如下:

    #include <iostream>
    #include <cmath>
    #include <cstdlib>
    #include <set>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <string>
    
    using namespace std;
    typedef long long LL;
    char s[5];
    
    int main(){
        int n, x;
        LL sum = 0, t;
        int ans = 0;
        scanf("%d %d", &n, &x);
        sum += x;
        for(int i = 0; i < n; ++i){
            scanf("%s", s);
            scanf("%lld", &t);
            if('+' == s[0])  sum += t;
            else {
                if(sum >= t)  sum -= t;
                else  ++ans;
            }
        }
        printf("%lld %d
    ", sum, ans);
        return 0;
    }
    
  • 相关阅读:
    整理—类型转换
    HTML简历
    数组
    选择语句2
    类型转换、运算符'
    C#(VS)基础
    hdu_1037(水题水疯了。。。史上最水)
    hdu_1033(我怎么找到的这么水的题,只为保存代码。。。)
    hdu_1030(数学题+找规律)
    hdu_1029_hash/map
  • 原文地址:https://www.cnblogs.com/dwtfukgv/p/5645463.html
Copyright © 2011-2022 走看看