3561 - 模拟4
电脑商场经营鼠标、键盘套件,如果成套购买,当购买数量大于或等于50套时,每套销售价格为450元;如果购买数量不足50套,则按每套500元进行销售;如果单独购买,键盘每只250元,鼠标每只300元。编写程序输入购买的键盘鼠标数量,计算购买得金额并输出。
提示:在购买商品时鼠标、键盘相同得数量则可视为成套,如鼠标35,键盘80,则可认为是35套鼠键+45只键盘。
Input
输入有多组样例。
输入购买的键盘和鼠标数量。
Output
输出金额。
Examples
Input
10 12 32 59
Output
5600 24100
Solution C
#include <stdio.h> #include <math.h> #include <stdlib.h> #include <time.h> int main() { // freopen("in","r",stdin); // freopen("out","w",stdout); int c,t; int m; while(scanf("%d%d",&c,&t)!=EOF) { if (c==t) { if (c>=50) m=c*450; else m=c*500; } else { if (c>t) { if (t>=50) m=t*450+(c-t)*250; else m=t*500+(c-t)*250; } else { if (c>50) m=c*450+(t-c)*300; else m=c*500+(t-c)*300; } } printf("%d\n",m); } return 0; }
Solution C++
#include <stdio.h> main() { int i,j,price; while (scanf("%d %d",&i,&j)!=EOF) { if (i==j) { if (i>=50) price=450*i; else price=500*i; } else { if (i>j) { if (j>=50) price=450*j+250*(i-j); else price=500*j+250*(i-j); } if (i<j) { if (i>=50) price=450*i+300*(j-i); else price=500*i+300*(j-i); } } printf("%d\n",price); } }