forked from daiwb/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1058Currency Exchange.cpp
More file actions
44 lines (40 loc) · 1.16 KB
/
1058Currency Exchange.cpp
File metadata and controls
44 lines (40 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iostream>
#include <iomanip>
using namespace std;
int main(void){
int m,n,t,i,j;
double rate[6][6];
double money;
long temp;
cin>>n;
for(t=0;t<n;t++){
if(t) cout<<endl;
for(i=1;i<=5;i++){
for(j=1;j<=5;j++){
cin>>rate[i][j];
}
}
while(cin>>m&&m!=0){
int* a=new int[m];
for(i=0;i<m;i++) cin>>a[i];
cin>>money;
money*=rate[1][a[0]];
temp=long(money*1000);
if(temp%10<5) money=(double)(temp/10)/100;
else money=(double)(temp/10+1)/100;
for(i=1;i<m;i++){
money*=rate[a[i-1]][a[i]];
temp=long(money*1000);
if(temp%10<5) money=(double)(temp/10)/100;
else money=(double)(temp/10+1)/100;
}
money*=rate[a[m-1]][1];
temp=long(money*1000);
if(temp%10<5) money=(double)(temp/10)/100;
else money=(double)(temp/10+1)/100;
cout<<setiosflags(ios::fixed)<<setprecision(2)<<money<<endl;
delete []a;
}
}
return 0;
}