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


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. 


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. 


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






#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)
	return 0;



Fifty Ways to Lose Your Data (and How to Avoid Them)

Fifty Ways to Lose Your Data (and How to Avoid Them)Linda Jolley and Jane Stroupe, SAS Institute Inc...

JavaCard free memory detect (how much memory left)

Problem / Requirement: You have a JavaCard and have full access to it, you want to know how much use...

How much training data do you need?

How much training data do you need?   转载至:https://medium.com/@malay.haldar/how-much-training-d...

How much memory does malloc(0) allocate?

原文:http://prog21.dadgum.com/179.html On most systems, this little C program will soak up all av...

How much the cost of an APP development?

Usually, people don’t understand the process of APP development and they also feel confused. How muc...

How much math does a GIS Analyst need to know?(转)

Trigonometry and spherical trigonometry. Let me surprise you: this stuff is overused. In many case...
  • kkk328
  • kkk328
  • 2012年10月02日 10:03
  • 1034

How Did Watson Answer?——Get Unstructured Textual Resource

本文主要讲述了IBM公司开发Watson系统过程中如何对文本信息就行获取、转换和拓展。主要参考文档为《Textual resource acquisition and engineering》。...

How Did Watson Answer? —— Deep Parsing

Watson中使用了两种分析器——ESG(English Slot Grammar)和PAS(Predicate-Argument Structure)。PAS建构在ESG之上,以支持更高层的语法分析...

How Did Watson Answer —— Final Merging and Ranking

一、摘要Watson答题处理流程的最后一步是答案的合并与排序。在这一步中,实现了按步骤划分并且可以逐次的机器学习框架,可以利用每一步中候选答案的评分,按照多个特征综合评分。 Watson中使用机器学...

How Did Watson Answer? —— Relation Extraction

一、摘要Waston中关系抽取通过两种方式进行——一是基于规则的模式匹配,二是基于统计模型的模式导出(pattern elicitation)。其中人工模式有30种,统计模式有7000种。之所以使用关...
您举报文章:POJ 2521:How much did the businessman lose