商店购物-题解

描述

小王同学接到一个任务,要去淘宝店里买笔,已知一支笔的价格是a元,小王同学有b元,请问小王同学最多能买到多少笔,如果没剩下钱,就输出“just enough”;如果剩余金额大于等于5元,就要上交,输出上交金额;如果剩余金额小于5元就算做是跑腿费,输出跑腿费。

输入描述

一行,包含两个整数 a,b 分别表示一支笔的价格和小王同学的钱数。

输出描述

第一行输出笔的个数 “pen:个数”

第二行如果钱正好输出 “just enough”

如果剩余金额需要上交,输出 “hand in:金额yuan”,如hand in:5yuan

如果剩余金额作为跑腿费,输出 “tips:金额yuan”,如tips:4yuan

代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <bits/stdc++.h>
using namespace std;

int main() {
int a, b;
cin >> a >> b;
int ans = b % a;
cout << "pen:" << b / a << endl;
if (ans == 0) {
cout << "just enough";
} else if (ans >= 5) {
cout << "hand in:" << ans << "yuan";
} else {
cout << "tips:" << ans << "yuan";
}

return 0;
}

商店购物-题解
https://chenxi-tijie.pages.dev/2025/07/商店购物-题解/
作者
chenxi
发布于
2025年7月2日
许可协议