top1编程
← 返回题目
题解

分糖果

1 条题解

  • 0
    @ 2026-7-29 0:19:44
    #include <iostream>
    using namespace std;
    
    int main() {
        int a, b, c, d, e;
        cin >> a >> b >> c >> d >> e;
        
        // 1号小朋友
        int temp = a / 3;  // 每份数量
        a = temp;          // 自己留一份
        b += temp;         // 给右边2号
        e += temp;         // 给左边5号
        
        // 2号小朋友
        temp = b / 3;
        b = temp;
        c += temp;         // 给右边3号
        a += temp;         // 给左边1号
        
        // 3号小朋友
        temp = c / 3;
        c = temp;
        d += temp;         // 给右边4号
        b += temp;         // 给左边2号
        
        // 4号小朋友
        temp = d / 3;
        d = temp;
        e += temp;         // 给右边5号
        c += temp;         // 给左边3号
        
        // 5号小朋友
        temp = e / 3;
        e = temp;
        a += temp;      
        d += temp;         
        cout << a << " " << b << " " << c << " " << d << " " << e << endl;   
        return 0;
    }
    
    • 1