發表文章

目前顯示的是 7月, 2022的文章

APCS實作題2022年6月第1題數字遊戲參考解法

若您覺得文章寫得不錯,請點選文章上的廣告,來支持小編,謝謝。 If you like this post, please click the ads on the blog or  buy me a coffee . Thank you very much. 題目連結  https://zerojudge.tw/ShowProblem?problemid=i399 。 題目說明 給三個介於 1 ~ 9 的整數 A1,A2,A3。 先輸出一個正整數 P 表示眾數數量,也就是出現最多次的數字的次數。 接下來將輸入的三個數字去除重複(剩下一個)後由大到小依序輸出。 範例一: 輸入 6 6 6 ,輸出 3 6。 因為出現最多次的數字是 6,共出現 3 次,並且只有出現 6 這個數字,因此輸出 3 6。 範例二: 輸入 7 9 7 ,輸出 2 9 7。 因為出現最多次的數字是 7,共出現 2 次,並且出現了 7 和 9,因為集合需要由大到小輸出,因此輸出 2 9 7。 範例三: 輸入 4 1 8 ,輸出 1 8 4 2。 因為三個數字各出現 1 次,集合由大到小輸出,因此輸出 1 8 4 1。 想法: 將輸入的數字記錄在陣列A。 用陣列或串列cnt紀錄數字 1 ~ 9 各自出現幾次。找次數陣列cnt中的次數最大值。 依次數值對陣列A由小排到大。 對陣列A,從最大值開始輸出不重複的數字, C++ 程式碼 #include <iostream> #include <algorithm> using namespace std; int main() {   const int N = 3;   int a[N];   while (cin >> a[0] >> a[1] >> a[2]) {     int cnt[10] = {0};  // 紀錄數字 1 ~ 9 各自出現幾次     // 算數字 1 ~ 9 各自出現幾次     for ( int i = 0; i < N; i++)       cnt[a[i]]++;  ...

高中生程式解題系統:e621: 1. 免費停車 (Free Parking)

若您覺得文章寫得不錯,請點選文章上的廣告,來支持小編,謝謝。 If you like this post, please click the ads on the blog or  buy me a coffee . Thank you very much. 題目連結 https://zerojudge.tw/ShowProblem?problemid=e621 。 想法: 用一個變數 hasFree 來記錄是否有免費停車位。 用迴圈來處理 大於A、小於B。 用取餘數運算子 % 與 if 來判斷是否被 C 整除。 C++ 參考程式碼 #include <iostream> using namespace std; int main() {   int N; // 幾天放送優惠   cin >> N;   int a, b, c;   while (N--) {     cin >> a >> b >> c;     bool hasFree = false ; // 是否有免費停車位       for ( int idx = a + 1; idx < b; idx++) { // 大於a、小於b       if ( idx % c != 0) { // 不被 c 整除         if (hasFree) cout << " " ;  // 因為已有免費車位,先輸出空白來區隔         hasFree = true ;           // 有免費車位         cout << idx;              // 輸出車位號碼       }     }  ...

程式設計營隊資料

圖片
0. 線上視訊網址: 課堂任務: https://studio.code.org/flappy/1?lang=zh-TW 1. Compute IT 闖關網址 https://compute-it.toxicode.fr/ right 右 → left 左 ← up 上 ↑ down 下 ↓ repeat 重複 if 如果 else 否則 while 當 again 再一次 2. Silent Teacher Python 3.  Little Dot Adventure 4. Code Combat 5.  Blockly Games 6. 一小時玩 Minecraft 教程 7. 藝術家 8.  星際大戰︰用程式碼建立銀河系