zoukankan      html  css  js  c++  java
  • A

    Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

    Description

    A soldier wants to buy w bananas in the shop. He has to pay k dollars for the first banana, 2k dollars for the second one and so on (in other words, he has to pay i·k dollars for the i-th banana).

    He has n dollars. How many dollars does he have to borrow from his friend soldier to buy w bananas?

    Input

    The first line contains three positive integers k, n, w (1  ≤  k, w  ≤  1000, 0 ≤ n ≤ 109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants.

    Output

    Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0.

    Sample Input

    Input
    3 17 4
    Output
    13

    题意:

    士兵去买香蕉,买的第一根香蕉的价格为k,第i根的价格为i*k。给定士兵带的钱和需要买的香蕉数目,求士兵要借多少钱,如果不用借钱,则输出0.(由于没有判断输出0的条件WA了一发..冤枉啊!!!!!)

    虽然是一道水题,但还是发出来劝解各位小伙伴和自己一定要认真读题,千万不要冤WA。

    还是附AC代码:

     1 #include<iostream>
     2 using namespace std;
     3 
     4 int a[1001];
     5 
     6 int main(){
     7      int k,n,w,sum=0;
     8      cin>>k>>n>>w;
     9     for(int i=1;i<=w;i++){
    10         a[i]=i*k;
    11         sum+=a[i];
    12     }
    13     if(sum-n>0)//!!!!!! 
    14     cout<<sum-n<<endl;
    15     else
    16     cout<<"0"<<endl;
    17     return 0;
    18 } 
  • 相关阅读:
    git教程学习笔记(1)
    一句话懂什么是JS闭包
    attachEvent和addEventListener 的使用方法和区别
    地址栏中多个问号如何处理
    事件委托用法
    rem和em的区别
    echarts事件中获取当前实例
    this经典试题
    获取浏览器选中文本并操作
    android Activity launch mode 一个实例 singleInstance
  • 原文地址:https://www.cnblogs.com/Kiven5197/p/5711643.html
Copyright © 2011-2022 走看看