SGU 152.Making round
不断向下取直到,忽略的数累计到一个百分比,给当前百分比加1。
这道题要避免处理浮点数,用余数来处理,不然会wa 9
#include <iostream> #include <cmath> using namespace std; int g[10001]; int x, n, sum, le; int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> g[i]; sum += g[i]; } for (int i = 1; i <= n; i++) { int k = g[i] * 100 / sum; le += g[i] * 100 - k * sum; g[i] = k; if (le >= sum) { le -= sum; g[i]++; } cout << g[i] << ' '; } }