How much did the businessman lose
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 9965   Accepted: 6749

Description

Businessmen, of course, can make much money. However, sometimes, they would lose money in trading. For example, Jame, a businessman, brought in some goods each cost him 40 yuan and he decided to sell at the price of 70 yuan. Then a customer came to buy one,
gave Jame 100 yuan, and of course got back 30 yuan. You may said, "Jame earned 30 yuan." But unfortunately, Jame found the 100 yuan from the customer was fake. What a poor man! In this case Jame lost 70 yuan (40 (the goods price) + 30 (the money paid back
to the customer)). 



Now your task is to calculate how much Jame would lose in this kind of trade. Of course in this case, sometimes Jame may still earn. 

Input

The input consists of several instances. Each instance contains four integers N, M, P and C, which are all in the range [0, 50000], separated by a single space. 



N is the cost price of Jame good. 

M is the sell price. 

P is the total fake money the customer gave Jame. 

C is how much Jame paid back to the customer. 



Here N < M. And P may be less than M, as customer may pay with some fake money and some true money. 



The input is terminated by a line containing 4 zeros. 

Output

For one instance, output one line contains exactly one integer, which tells how much Jame lost in the trade. If Jame still earned, just output a negative integer, the absolute value of which tells the money Jame earned.

Sample Input

40 70 100 30
40 70 50 20
14604 32391 3902 153
0 0 0 0

Sample Output

70
20
-13885

水题,商贩花N元买了一个商品,卖M元,买的人给了商贩P元的假币,C是商贩找回给买家的真钞。

问整个过程中商贩赔了多少钱。

赔的钱=N-(M-P+C)+C=N-M+P

代码:。。。

#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std; int main()
{
int n,m,p,c;
while(cin>>n>>m>>p>>c && n+m+p+c)
{
cout<<n-m+p<<endl;
}
return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

POJ 2521:How much did the businessman lose的更多相关文章

  1. POJ 3321:Apple Tree + HDU 3887:Counting Offspring(DFS序+树状数组)

    http://poj.org/problem?id=3321 http://acm.hdu.edu.cn/showproblem.php?pid=3887 POJ 3321: 题意:给出一棵根节点为1 ...

  2. POJ 3252:Round Numbers

    POJ 3252:Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10099 Accepted: 36 ...

  3. POJ 1459:Power Network(最大流)

    http://poj.org/problem?id=1459 题意:有np个发电站,nc个消费者,m条边,边有容量限制,发电站有产能上限,消费者有需求上限问最大流量. 思路:S和发电站相连,边权是产能 ...

  4. POJ 3436:ACM Computer Factory(最大流记录路径)

    http://poj.org/problem?id=3436 题意:题意很难懂.给出P N.接下来N行代表N个机器,每一行有2*P+1个数字 第一个数代表容量,第2~P+1个数代表输入,第P+2到2* ...

  5. POJ 2195:Going Home(最小费用最大流)

    http://poj.org/problem?id=2195 题意:有一个地图里面有N个人和N个家,每走一格的花费是1,问让这N个人分别到这N个家的最小花费是多少. 思路:通过这个题目学了最小费用最大 ...

  6. POJ 3281:Dining(最大流)

    http://poj.org/problem?id=3281 题意:有n头牛,f种食物,d种饮料,每头牛有fnum种喜欢的食物,dnum种喜欢的饮料,每种食物如果给一头牛吃了,那么另一个牛就不能吃这种 ...

  7. POJ 3580:SuperMemo(Splay)

    http://poj.org/problem?id=3580 题意:有6种操作,其中有两种之前没做过,就是Revolve操作和Min操作.Revolve一开始想着一个一个删一个一个插,觉得太暴力了,后 ...

  8. POJ 3237:Tree(树链剖分)

    http://poj.org/problem?id=3237 题意:树链剖分.操作有三种:改变一条边的边权,将 a 到 b 的每条边的边权都翻转(即 w[i] = -w[i]),询问 a 到 b 的最 ...

  9. POJ 2763:Housewife Wind(树链剖分)

    http://poj.org/problem?id=2763 题意:给出 n 个点, n-1 条带权边, 询问是询问 s 到 v 的权值, 修改是修改存储时候的第 i 条边的权值. 思路:树链剖分之修 ...

随机推荐

  1. Python 2 与 3 共存了 11 年,新年就要和它道别

    在 Python 3.9 都已经进入 dev 版本的 2020 年,Python 2 终于要和我们告别了. 2 and 3 Python 2 第一个版本发布于 2000 年 10 月 16 日,到今年 ...

  2. vue中使用矢量图

    1.打开矢量图库,将需要的图表添加至购物车 2.将购物车的图标添加到一个项目中(便于后期增加更新)并下载至本地 3.将这四个文件及iconfont.css添加至项目的assets中 4.打开iconf ...

  3. UDP单播、多播、广播

    一.UDP广播 广播使用的特殊的IP地址:最后一位是255时的IP地址是给广播预留的IP地址,如:192.168.88.255 广播UDP与单播UDP的区别就是IP地址不同,广播使用广播地址255.2 ...

  4. 二 SVN代码冲突的解决

    问题: A和B都是最新的代码,A修改了代码提交了,B也修改了代码,但是B提交的时候出现冲突的问题. 解决方案:编辑冲突 解决冲突: 方法一:将文件里面冲突的描述去掉,重新提交 方法二:软件解决冲突

  5. 题解 zr1212 【20WC集训】货币

    题目链接 我们给每个连通块图上一种颜色.不同的连通块涂不同的颜色. 首先,我们定义\(f_r\)表示:使\([l,r]\)包括\([1,r]\)里所有颜色的最大的\(l\). 然后我维护一个变量\(p ...

  6. 火狐中添加selenium IDE

    在火狐中添加selenium IDE 1.下载selenium IDE,此处下载的是selenium-ide-2.5.0.xpi 2.在火狐中,打开菜单-->附加组件-->用户附加组件的工 ...

  7. P1070 结绳

    P1070 结绳 转跳点:

  8. CodeForces - 869B The Eternal Immortality

    题意:已知a,b,求的最后一位. 分析: 1.若b-a>=5,则尾数一定为0,因为连续5个数的尾数要么同时包括一个5和一个偶数,要么包括一个0. 2.若b-a<5,直接暴力求即可. #in ...

  9. input type="submit" 和"button"有什么区别

    HTML中<input type="submit" /> 和 <input type="button" /> 主要从元素定义类型.点击触 ...

  10. git杂碎汇总

    1. .gitignore文件使用 1.如果不想某类文件(编译后.配置等文件)加入到git版本管理,可以在这个文件中配置规则,进行过滤筛选: 2.配置规则 以斜杠"/"表示目录:e ...