百元买笔 在三个变量中寻找中间量为基础 去表示其他两个量
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
bool found = false;
for (int steel = 1; steel <= n; ++steel) {
for (int ballpoint = 1; ballpoint <= n; ++ballpoint) {
int pencil = n - steel - ballpoint;
if (pencil >= 1 && (3 * steel + 2 * ballpoint + 0.5 * pencil) == n) {
found = true;
cout << steel << " " << ballpoint << " " << pencil << endl;
}
}
}
if (!found) {
cout << "Not found!" << endl;
}
return 0;
}