Skip to content

Commit 4ddd7da

Browse files
committed
Add olinfo task coinchange: 100/100
1 parent 256ce49 commit 4ddd7da

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

olinfo/coinchange/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# [Coin Change (coinchange)](https://training.olinfo.it/#/task/ois_coinchange/statement)
2+
Score: 100/100

olinfo/coinchange/main.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#pragma GCC optimize ("O3")
2+
#include <bits/stdc++.h>
3+
using namespace std;
4+
5+
#define int int64_t
6+
#define float long double
7+
8+
ifstream in{"input.txt"};
9+
ofstream out{"output.txt"};
10+
#ifdef DEBUG
11+
template<class A,class B>ostream&operator<<(ostream&o,const pair<A,B>&p){cout<<"("<<p.first<<", "<<p.second<<")";return o;}
12+
template<class T,typename=typename enable_if<!is_same<T, string>::value,decltype(*begin(declval<T>()))>::type>ostream&operator<<(ostream&o,const T&v){cout<<"[";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin()){cout<<", ";}cout<<*it;}cout<<"]";return o;}
13+
void deb(){cout<<"\n";}template<class T,class...Ts>void deb(const T&t,const Ts&...args){cout<<t;if(sizeof...(args)!=0){cout<<" ";}deb(args...);}
14+
#else
15+
#define deb(...)
16+
#endif
17+
18+
constexpr int vals[15] = {1, 2, 5, 10, 20, 50, 1'00, 2'00, 5'00, 10'00, 20'00, 50'00, 100'00, 200'00, 500'00};
19+
20+
signed main() {
21+
int tot=0;
22+
for(int i=0;i<15;++i){
23+
int v;
24+
in>>v;
25+
tot+=vals[i]*v;
26+
}
27+
28+
int res[15];
29+
for(int i=14;i>=0;--i){
30+
res[i]=tot/vals[i];
31+
tot%=vals[i];
32+
}
33+
34+
for(int i=0;i<15;++i){
35+
out<<res[i]<<" ";
36+
}
37+
}

0 commit comments

Comments
 (0)