【发布时间】:2021-11-25 21:28:12
【问题描述】:
我有一个计算变化的 C++ 代码。
它接受输入,并根据接收变化的方式返回输出。
我需要在最后一次更改输出后删除 + 号。
有没有办法做到这一点?
我的代码:
if (n500 > 0) {
cout << n500 << " x 500 + ";
}
if (n200 > 0) {
cout << n200 << " x 200 + ";
}
if (n100 > 0) {
cout << n100 << " x 100 + ";
}
if (n50 > 0) {
cout << n50 << " x 50 + ";
}
if (n20 > 0) {
cout << n20 << " x 20 + ";
}
if (n10 > 0) {
cout << n10 << " x 10 + ";
}
if (n5 > 0) {
cout << n5 << " x 5 + ";
}
if (n2 > 0) {
cout << n2 << " x 2 + ";
}
if (n1 > 0) {
cout << n1 << " x 1 + ";
}
return 0;
}
【问题讨论】: