鸡北长

宇的成就  •  3天前


//商店老板一共有4种面值的纸币,每种面值的纸币都有无数张。 //四种纸币面值分别为:第一种面值为20元,第二种面值为10元, //第三种面值为5元,第四种面值为1元。 //现在老板需要给顾客找零钱,并希望找给顾客的纸币张数越少越好。 //请你告诉老板总的需要找给顾客多少张纸币以及需要用到几种面值 //的纸币。

include <stdio.h>

int main() {

int money, total_count = 0, total_type = 0;
int count_20 = 0, count_10 = 0, count_5 = 0, count_1 = 0;

scanf("%d", &money);

count_20 = money / 20;
money = money % 20;
total_count = total_count + count_20;
if (count_20 > 0) {
	total_type += 1;
}

count_10 = money / 10;
money = money % 10;
total_count = total_count + count_10;
if (count_10 > 0) {
	total_type += 1;
}
count_5 = money / 5;
money = money % 5;
total_count = total_count + count_5;
if (count_5 > 0 ) {
	total_type += 1;
}
count_1 = money / 1;
total_count = total_count + count_1;
if (count_1 > 0 ) {
	total_type += 1;
}

printf("%d %d", total_count, total_type);
return 0;

}


评论:

请先登录,才能进行评论