Codeforces 686A free Ice Cream (water problem Simulation)

Source: Internet
Author: User

Test instructions: Given the initial amount of ice cream, then n operations, if "+", then the number will increase, if "-", if the existing quantity is greater than or equal to the amount to be reduced, then subtract, if less than,

Then the child will leave home. Ask you how many ice creams you have left, and the number of kids that are leaving.

Analysis: A problem of multi-water, is a simulation, if it is +, plus, if it is '-', to judge, if not enough, record down.

The code is as follows:

#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\n", sum, ans);    return 0;}

Codeforces 686A free Ice Cream (water problem Simulation)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.