Skip to content

Instantly share code, notes, and snippets.

@sealddr
Last active Oct 7, 2017
Embed
What would you like to do?
#include <iostream>
using namespace std;
int main(void){
int c1, c5, c10, c50, c100, c500;
int A;
cin >> c1 >> c5 >> c10 >> c50 >> c100 >> c500 >> A;
int n1, n5, n10, n50, n100, n500;
int sum=0;
for(n500=0; n500<c500; n500++){
if(sum+500 > A){
break;
}else{
sum += 500;
}
}
for(n100=0; n100<c100; n100++){
if(sum+100 > A){
break;
}else{
sum += 100;
}
}
for(n50=0; n50<c50; n50++){
if(sum+50 > A){
break;
}else{
sum += 50;
}
}
for(n10=0; n10<c10; n10++){
if(sum+10 > A){
break;
}else{
sum += 10;
}
}
for(n5=0; n5<c5; n5++){
if(sum+5 > A){
break;
}else{
sum += 5;
}
}
for(n1=0; n1<c1; n1++){
if(sum+1 > A){
break;
}else{
sum += 1;
}
}
int count = n1+n5+n10+n50+n100+n500;
cout << count << endl;
cout << "1 yen * " << n1 << endl;
cout << "5 yen * " << n5 << endl;
cout << "10 yen * " << n10 << endl;
cout << "50 yen * " << n50 << endl;
cout << "100 yen * " << n100 << endl;
cout << "500 yen * " << n500 << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment