1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > 每日一题 Day8:CodeForces-996A.Hit the Lottery(贪心)

每日一题 Day8:CodeForces-996A.Hit the Lottery(贪心)

时间:2023-04-07 18:30:01

相关推荐

每日一题 Day8:CodeForces-996A.Hit the Lottery(贪心)

原题链接

因为数据太水,我直接一发暴力过了......

#include <cstdio>using namespace std;int value[5] = {100, 20, 10, 5, 1};int main() {int n, ans = 0;scanf("%d", &n);while(n > 0) {for(int i = 0; i < 5; i ++) {if(n >= value[i]) {ans ++;n -= value[i];break;}}}printf("%d\n", ans);return 0;}

#include <cstdio>using namespace std;int value[5] = {100, 20, 10, 5, 1};int main() {int n, ans = 0;scanf("%d", &n);for(int i = 0; i < 5; i ++) {if(n >0) {ans += (n / value[i]);n = n % value[i];}}printf("%d\n", ans);return 0;}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。