POJ 2521:How much did the businessman lose

原创 2015年07月11日 10:37:42

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;
}




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

poj2521

#include #include using namespace std; int main(){ //ifstream cin("1.txt"); int n,m,p,c; ...
  • u010738033
  • u010738033
  • 2014年02月25日 22:15
  • 335

Mac MySQL设置密码

2017-06-12T10:21:47.854165Z 1 [Note] A temporary password is generated for root@localhost: (L5odkk/w...
  • chmod_R_755
  • chmod_R_755
  • 2017年06月12日 18:45
  • 391

java 统计文本中出现概率最高的10个字符串!!

以前经常在CSDN博客上看别人的文章,有时是遇到难题为了寻找思路,有时则是为了偷懒,直接复制别人的源代码,所以对于写这些博客的技术大神,我都是佩服且感激的。感激于他们把我的问题分析的如此透彻明白,佩服...
  • unexisted_
  • unexisted_
  • 2014年10月21日 20:48
  • 3562

POJ 2387 图论之最短路【三种写法】

最短路问题; 坑点1:是先输入边,再输入点; 坑点2:数据很大,不适合用别的模板; 坑点3:有重边 需要判定; Description Bessie is out in the field and...
  • qq_33638791
  • qq_33638791
  • 2016年03月13日 00:05
  • 1261

从源码分析java集合【ArrayList】

ArrayList的内部实现其实就是我们熟悉的数组,它继承了AbstractList,实现了List,RandomAccess,Cloneable和Serializable接口。 RandomAcce...
  • u010233260
  • u010233260
  • 2015年04月26日 20:50
  • 539

POJ 题目2761 Feed the dogs(主席树||划分树)

Feed the dogs Time Limit: 6000MS   Memory Limit: 65536K Total Submissions: 16860   ...
  • yu_ch_sh
  • yu_ch_sh
  • 2015年08月23日 20:58
  • 800

too much data for RSA block .关于RSA算法密钥长度/密文长度/明文长度

今天在做RSA加密的时候遇到了一个这样的错误:ArrayIndexOutOfBoundsException: too much data for RSA block 查询相关资料后得知该错误是加密数...
  • centralperk
  • centralperk
  • 2013年01月29日 19:01
  • 23190

java 数据库编程

java与数据库交互的主要API是jdbc。jdbc的主要目的是: 1.通过使用SQL或者专有的SQL扩展,程序员可以利用java语言开发访问数据的应用。 2.数据库开发商或者数据库工具开...
  • losefrank
  • losefrank
  • 2015年05月26日 19:05
  • 147

HDU2521 反素数【因子数量+打表+水题】

反素数 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submis...
  • tigerisland45
  • tigerisland45
  • 2017年06月29日 06:27
  • 650

cenos7 的gitlab 搭建和遇到的坑

一直都说自己搭建gitlab的,但是由于上次使用vagrant搭建gitlab的时候就遇到了坑,所以就搁置了,现在把搭建vagrant一起重新写一下。 一、vagrant 环境的搭建 1、window...
  • it_lihongmin
  • it_lihongmin
  • 2017年06月11日 16:28
  • 1457
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:POJ 2521:How much did the businessman lose
举报原因:
原因补充:

(最多只允许输入30个字)