标签:blog class code int http string
#include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX_VALUE 0x7FFFFFFF int min_value(int *dp, int loc) { int one, two, five, ten, twenty, fifty, hundred, min; one = loc - 1 >= 0 ? dp[loc - 1] + 1 : MAX_VALUE; two = loc - 2 >= 0 ? dp[loc - 2] + 1 : MAX_VALUE; five = loc - 5 >= 0 ? dp[loc - 5] + 1 : MAX_VALUE; ten = loc - 10 >= 0 ? dp[loc - 10] + 1 : MAX_VALUE; twenty = loc - 20 >= 0 ? dp[loc - 20] + 1 : MAX_VALUE; fifty = loc - 50 >= 0 ? dp[loc - 50] + 1 : MAX_VALUE; hundred = loc - 100 >= 0 ? dp[loc - 100] + 1 : MAX_VALUE; min = one; if (min > two) { min = two; } if (min > five) { min = five; } if (min > ten) { min = ten; } if (min > twenty) { min = twenty; } if (min > fifty) { min = fifty; } if (min > hundred) { min = hundred; } return min; } int calculate_num(int p) { int *dp = (int *)malloc(sizeof(int) * (p + 1)); dp[0] = 0; int i; for (i = 1; i <= p; i ++) { dp[i] = min_value(dp, i); } return dp[p]; } int main(void) { int p, res; while (scanf("%d", &p) != EOF) { res = calculate_num(p); printf("%d\n", res); } return 0; }
#include <stdio.h> #include <stdlib.h> #include <string.h> int calculate_num(int p) { int money[7] = {1, 2, 5, 10, 20, 50, 100}; int i, tmp, num = 0; for (i = 6; i >= 0; i --) { if (p >= money[i]) { tmp = p / money[i]; p = p % (tmp * money[i]); num += tmp; } } return num; } int main(void) { int p, res; while (scanf("%d", &p) != EOF) { res = calculate_num(p); printf("%d\n", res); } return 0; }
[九度OJ]货币问题,解题报告,布布扣,bubuko.com
标签:blog class code int http string
原文地址:http://blog.csdn.net/wzy_1988/article/details/25044061