發表文章

目前顯示的是 11月, 2023的文章

f605. 1. 購買力

f605. 1. 購買力 |  題目連結 :  https://zerojudge.tw/ShowProblem?problemid=f605 |  解題思路 : 用min,max函式找出最大最小值,方便判斷相差多少 |  程式碼 :  /* f605. 1. 購買力 https://zerojudge.tw/ShowProblem?problemid=f605 skyblue AC (2ms, 348KB) */ #include <bits/stdc++.h> using namespace std; int main(){ int n, d; scanf("%d%d", &n, &d); int a,b,c; //times記錄物件數(買了多少東西) int times = 0; //total記錄總價錢 int total = 0; while(n--){ scanf("%d%d%d", &a,&b,&c); //用min,max函式找出最大最小值 int mi = min({a,b,c}); int ma = max({a,b,c}); //若最大最小值相差超過d,物件數+1,金額加三者的平均數 if(ma - mi >= d){ times ++; total += (a+b+c)/3; } } //輸出物件數及總價格 printf("%d %d", times,total); return 0; } /* 範例輸入 #1 1 3 24 27 21 範例輸出 #1 1 24 範例輸入 #2 3 4 24 33 42 51 48 60 77 77 77 範例輸出 #2 2 86 */

d066.上學去吧!

d066.上學去吧! |  題目連結 :  https://zerojudge.tw/ShowProblem?problemid=d066 |  解題思路 : if - else判斷 (如程式中註解) |  程式碼 :  /* d066. 上學去吧! https://zerojudge.tw/ShowProblem?problemid=d066 skyblue AC (3ms, 344KB) */ #include <bits/stdc++.h> using namespace std; int main(){ //hh為時,mm為分 int hh; int mm; scanf("%d%d", &hh, &mm); //8:00到17:00前一定在校 if(hh >= 8 && hh < 17){ printf("%s", "At School"); } //7:30以後才算到校 else if(hh == 7 && mm >= 30){ printf("%s", "At School"); } //若好17:00算放學 else if(hh == 17){ printf("%s", "Off School"); } else{ printf("%s", "Off School"); } return 0; }

f071. 2. 刮刮樂 (Lottery)

f071. 2. 刮刮樂 (Lottery) |  題目連結 :  https://zerojudge.tw/ShowProblem?problemid=f071 |  解題思路 : (如程式中註解) |  注意 : 如範例測資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

a147.Print it all

a147.Print it all |  題目連結 :  https://zerojudge.tw/ShowProblem?problemid=a147 |  解題思路 : 用while迴圈重複輸入n,for迴圈中,如果小於n的i值不可被7整除則輸出 |  程式碼 :  /* a147. Print it all skyblue https://zerojudge.tw/ShowProblem?problemid=a147 AC (6ms, 304KB) */ #include <bits/stdc++.h> using namespace std; int main(){ int n; while(cin >> n){ if(n>0){ for(int i=1; i<n; i++){ if(i%7 != 0){ cout << i <<" "; } } cout << "\n"; } else if(n == 0) break; } return 0; }

a053.計分程式

a053.計分程式 |  題目連結 :  https://zerojudge.tw/ShowProblem?problemid=a053 |  解題思路 : 設題數為n,判斷n的區間,輸出相對應分數 |  程式碼 :  /* a053 計分程式 skyblue https://zerojudge.tw/ShowProblem?problemid=a053 AC (2ms, 356KB) */ #include <bits/stdc++.h> using namespace std; int main(){ //輸入輸出加速語法 ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; if(n<=10) cout << n*6 <<"\n"; if((n>= 11) && (n<=20)) cout << 60 + (n-10)*2 <<"\n"; if((n>= 21) && (n<=40)) cout << 80 + (n-20) <<"\n"; if(n>40) cout << 100<<"\n"; return 0; }

a104.排序

a104.排序 |  題目連結 :  https://zerojudge.tw/ShowProblem?problemid=a104 |  解題思路 : sort 函式 |  程式碼 :  /* a104. 排序 https://zerojudge.tw/ShowProblem?problemid=a104 sss 2023/10/3 AC (4ms, 316KB) */ #include <bits/stdc++.h> using namespace std; int main(){ int n; while(scanf("%d", &n) != EOF){ int a[1005] = {0}; for(int i=0; i<n; i++){ scanf("%d", &a[i]); } sort(a, a+n); printf("%d",a[0]); for(int i=1; i<n; i++){ printf(" %d", a[i]); } printf("\n"); } return 0; }

a034.二進位轉換

a034.二進位轉換 |  題目連結 :  https://zerojudge.tw/ShowProblem?problemid=a034 |  解題思路 : 先知道十進位轉二進位的方法,開一個陣列紀錄每一位處理好的數,再從陣列的最後一個數開始輸出 |  程式碼 :  /* /* a034二進位轉換 skyblue AC (2ms, 324KB) */ #include <bits/stdc++.h> using namespace std; int main(){ int n; int a[50]; while(scanf("%d", &n) != EOF){ int i = 0; //轉換成二進位 while(n > 0){ a[i] = n%2; n /= 2; i++; } //從陣列的最後一個數開始輸出 for(int c = i-1; c>=0; c--){ printf("%d", a[c]); } printf("\n"); } return 0; }

a003. 兩光法師占卜術

 a003. 兩光法師占卜術 |  題目連結 :  https://zerojudge.tw/ShowProblem?problemid=a003 |  解題思路 : 簡易if-else判斷 |  程式碼 :  /* a003. 兩光法師占卜術 https://zerojudge.tw/ShowProblem?problemid=a003 skyblue AC (11ms, 356KB) */ #include <bits/stdc++.h> using namespace std; int main(){ int m, n; scanf("%d%d", &m, &n); int s; s = (m*2 + n)%3; if(s == 0) printf("普通"); else if(s == 1) printf("吉"); else if (s == 2) printf("大吉"); return 0; }