資料結構›Ch1 演算法基礎
第 27 題/共 57 題
◀ DS 27/57
27. C++ Procedure、Reverse Engineering
#DS-01-027中C++ ProcedureReverse Engineering
題組題幹(本題:⑯,共 2 小題)點擊展開

Consider the following C++ procedure.

int sum(long long n)
{
    int result = 0;
    while (n) {
        result += n % 10;
        n /= 10;
    }
    return result;
}

long long foo(long long n, int target)
{
    long long x = n, y = 1;
    while (sum(n) > target) {
        n = n / 10 + 1;
        y *= 10;
    }
    return n * y - x;
}

What is the most likely problem statement with the above C++ procedures as a solution?

📄 交大113
跳轉到第題
▤完整推導請見《WH 資工筆記 · 資料結構》Ch1 演算法基礎
本章題號 · 21–40 / 57