题解 | #找零#

找零

http://www.nowcoder.com/practice/944e5ca0ea88471fbfa73061ebe95728

自存

#include <bits/stdc++.h>

using namespace std;

int main() {
    int n;
    cin >> n;
    int price[] = {64, 16, 4, 1};
    int count[4] = {0};
    //1元、4元、16元、64元,花200,需要找零824块,找12个64元硬币,3个16元硬币,2个4元硬币即可。
	//     cout << "花" << n << ",";

    n = 1024 - n;

    for (int i = 0; i < 4; ++i) {
        count[i] = n / price[i];
        n %= price[i];
    }

//        cout << "需要找零" << n << "块";
//        if (n){
//            cout << ","<< "找" ;
//            if (count[0])cout << count[0] << "个64元硬币";
//            if (count[1])cout << ","<< count[1] << "个16元硬币";
//            if (count[2])cout << ","<< count[2] << "个4元硬币" ;
//            if (count[3])cout << ","<< count[3] << "个1元硬币" ;
//        }
//        cout << "即可。";

    int c = 0;
    for (int i = 0; i < 4; ++i) {
        c += count[i];
    }
    cout << c << endl;
}
全部评论

相关推荐

01-12 09:24
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务