poj 2521 How much did the businessman lose
来源:互联网 发布:js bigdecimal 计算 编辑:程序博客网 时间:2024/06/03 20:02
Language:
How much did the businessman lose
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 10930 Accepted: 7123
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.
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.
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 3040 70 50 2014604 32391 3902 1530 0 0 0
题目解析:
本题的大概意思是,一个商人卖货收到价钱,计算最终赔了多少或者赚了多少。
我的解决办法是,
1,先计算商人从腰包里拿出来多少钱,也就是商品的进货价格+付给客户的价格
2,接下来计算商人得到的真钱有多少,也就是商人给客户的钱+商品的售价-商人给的假钱
3,最后计算两个的差值,就是所要求得。
再计算
代码:
#include<iostream>using namespace std;int main(){ int N,M,P,C; while(cin>>N>>M>>P>>C&&N!=0||M!=0||P!=0||C!=0) { cout<<N+C-(M+C-P)<<endl; } return 0;}
0 0
- POJ 2521 How much did the businessman lose
- POJ 2521:How much did the businessman lose
- POJ 2521 How much did the businessman lose G++
- poj 2521 How much did the businessman lose
- poj2521 How much did the businessman lose
- PKU 2521 How much did the businessman lose这道题太水了………………
- How did the term BOOTING come from
- How much common sense have YOU got? Take the test
- the lose of Titanic
- checkio (How much gold)
- How much the cost of an APP development?
- How Did Watson Answer?
- 408. The fox knew too much, that is how he lost his tail. 机关算尽太聪明,反误了卿卿性命
- lose at the starting line again
- 《East Turkestan Independence Movement》《How Did The Sun Rise Over Yanan》《贪婪的大脑》《空谷幽兰》
- How Much Is My Blog Worth?
- How Much Sleep Do I Need?
- How much you really want to succeed
- js面试题
- HTTP协议
- 栈的压入、弹出序列
- mybatis高级输出映射(一对一查询输出映射)
- 二叉树前序、中序、后序遍历非递归写法的透彻解析
- poj 2521 How much did the businessman lose
- HttpClient之配置ssl,采用绕过证书验证实现https
- 2017 实习生 阿里巴巴 java开发工程师笔试题 字符串匹配
- ATM面向对象的分析与设计之——分析类图
- LeetCode115 Distinct Subsequences
- steam vr 手柄的交互
- LeetCode116 Populating Next Right Pointers in Each Node
- POJ2313 Sequence
- MySQL 安装和启动服务,“本地计算机 上的 MySQL 服务启动后停止。某些服务在未由其他服务或程序使用时将自动停止。”