f071. 2. 刮刮樂 (Lottery)
f071. 2. 刮刮樂 (Lottery)
| 解題思路 : (如程式中註解)
| 注意 : 如範例測資3,27、36皆出現2次,故贏得金額為500+500+500+500 = 2000
| 程式碼 :
/*
f071. 2. 刮刮樂 (Lottery)
https://zerojudge.tw/ShowProblem?problemid=f071
skyblue
AC (2ms, 348KB)
*/
#include <bits/stdc++.h>
using namespace std;
int main(){
//開3個陣列,分別記錄[幸運數字]、[號碼區的號碼]、[對應金額]
int a[3];
int b[5];
int c[5];
//mon 為贏得的金額
int mon = 0;
//分別輸入值
for(int i = 0; i<3; i++){
scanf("%d", &a[i]);
}
for(int i = 0; i<5; i++){
scanf("%d", &b[i]);
}
for(int i = 0; i<5; i++){
scanf("%d", &c[i]);
}
//若前兩個幸運數字與號碼區數字符合,mon += 對應金額
for(int i = 0; i<5; i++){
if(a[0] == b[i]){
mon += c[i];
}
}
for(int i = 0; i<5; i++){
if(a[1] == b[i]){
mon += c[i];
}
}
//yes代表第三個數是否有在號碼區中
//若有,yes質變為true
bool yes = false;
for(int i = 0; i<5; i++){
if(a[2] == b[i]){
yes = true;
mon -= c[i];
}
}
//若yes值為false,代表第三個數字沒在號碼區中,mon加倍
if(!yes) mon *= 2;
//若mon > 0,輸出mon,否則輸出0
if(mon >= 0) printf("%d", mon);
else printf("0");
return 0;
}
留言
張貼留言