华为OJ基础篇-百钱买百鸡问题

公元前五世纪,我国古代数学家张丘建在《算经》一书中提出了“百鸡问题”:鸡翁一值钱五,鸡母一值钱三,鸡雏三值钱一。百钱买百鸡,问鸡翁、鸡母、鸡雏各几何?

void hwOJ(){
    int c = 0,t=0;
    cin >> c;
    t = c * 100;
    int a1 = 0, a2 = 0, a3 = 0;
    int z = 0;
    a1 = 20 * c; a2= 33 * c;
    for (int i = 0; i <= a1; ++i)
        for (int j = 0; j <= a2; ++j)
        {   
            z = t- i - j;
            if (z % 3 == 0 && i * 5 + j * 3 + z / 3 == t){
                cout << i << " " << j << " " << z << endl;
            }
        }
    cout << endl;
}

你可能感兴趣的:(C++)