/* @tier hard @module ac @transform acquire-util */ /* * ac_cu_0006.c - 매입 공통 유틸리티 (plain C) [tier=hard] */ #include "ac_cu_0006.h" #include /* 디지털 루트(각 자리 합 반복) 계산 */ static int ac_cu_0006_droot(long v) { if (v < 0) v = -v; while (v >= 10) { long s = 0; while (v > 0) { s += v % 10; v /= 10; } v = s; } return (int)v; } /* 수수료: 정률 계산 후 상한(cap) 적용 */ long ac_cu_0006_fee(long amount, int rate_bp) { long fee, cap = 50000L; if (amount <= 0 || rate_bp < 0) return 0; fee = amount * (long)rate_bp / 10000L; if (fee > cap) fee = cap; return fee; } /* 이중 절사: 1차 절사 후 잔여 2/3 이상이면 한 단위 보정 */ long ac_cu_0006_round_unit(long amount, long unit) { long f1; if (unit <= 0) return amount; f1 = (amount / unit) * unit; if ((amount - f1) * 3 >= unit * 2) f1 += unit; return f1; } /* 분류: 디지털 루트(1~9, 0) */ int ac_cu_0006_classify(long amount) { return ac_cu_0006_droot(amount); }