<h2 class="text-center">CPE 檢定加強計畫(一)</h2> <h3 class="text-center">計畫介紹與 C++ 基礎語法</h3> <style> :root{ --r-main-font-size: 30px; } .reveal .slides { text-align: left; } /* .ul-left { display: block !important; margin:0 0 0 0.5em !important; } */ .hint { color: #191919; } details[open] { margin-top: 1.5em; } details[open] .hint { color: inherit; } details[open] .hint::after { content: ":"; } </style> ---- ### Table of Contents - CPE 檢定介紹 - 課程介紹 - C++ 基礎語法 - 基本例題講解 --- <h2 class="text-center">CPE 檢定介紹</h2> ---- ### [CPE][CPE] 檢定 - 全名:大學程式能力檢定 - 適合大學生 - 每年會舉辦四次 - 取得參加 ICPC 資格的管道之一 - 題目皆出自 Online Judge(舊稱 Uva) - 題目會依照難度分成五個等級(一~五星) 官方的完整介紹:[傳送門][CPE_detail] <!-- .element: class="fragment" data-fragment-index="1" --> [CPE]: https://cpe.cse.nsysu.edu.tw/ [CPE_detail]: https://cpe.cse.nsysu.edu.tw/doc/CPE_introduction.pdf ---- 由於一星題都是固定的題目(共49題) 且考試題目的七題中至少有一題選自一星題 二星題的出題邏輯也非常類似 因此一、二星較好掌握 --- <h2 class="text-center">課程介紹</h2> ---- ### 課程資訊 - 開課日期:9/18(三)、9/25(三)、10/2(三)、10/9(三) - 時間:晚上 6:30 ~ 9:30 - 講義:放在 [HackMD](https://hackmd.io/@CPE-GOGO/Sk3NBQR5C) - 題目:放在 [vjudge](https://vjudge.net/group/cpe-gogogo?r=m2tctrzfbrbCSzjBVYe5) ---- ### 講師:陳上恩 - CPE 檢定 專業級 (4/7) - 2023 TOPC Honorable - 2024 海洋盃消波塊組 佳作 - 台聚集團第四梯次 IT 實習生 - ~~北科大程式社 社長的好朋友~~ - ~~在 HP Codewars 抽過筆電~~ <img src="https://hackmd.io/_uploads/r18XK2eo0.png" style="position: absolute; right: 0px; top: 30px; width: 300px; height: 300px"> ---- ### 助教:郭浩 - CPE 檢定 進階級 (3/7) - 2023 TOPC Honorable - 2024 海洋盃消波塊組 佳作 - APCS 觀念 4 級、實作 3 級 - 187 cm - ~~(他的高中同學)擁有山豬駕駛執照~~ <img src="https://hackmd.io/_uploads/HJeOSpgsR.png" style="position: absolute; right: 0px; top: 30px; width: 200px; height: 200px"> ---- ### 助教:黃俊源 - CPE 檢定 專業級 (4/7) - 2023 TOPC Honorable - 2024 海洋盃消波塊組 佳作 - APCS 觀念 4 級、實作 3 級 - 111 新北資訊學科能力競賽 佳作 - 擅長使用 Python --- <h2 class="text-center">C++ 基礎語法</h2> ---- 這單元只是作為複習用途 請不要以為是 C++ 速成班 ---- ### C++ 萬能標頭檔 ```cpp #include <bits/stdc++.h> using namespace std; int main() { return 0; } ``` \*Visual Studio 的編譯器 (MSVC) 不支援此標頭檔 ---- ### 輸入 程式碼 ```cpp int a; cin >> a; // 輸入一個數字 ``` ---- ### 輸出 程式碼 ```cpp int a = 202; double f = 87.5487123; cout << a << '\n'; // 輸出 + 換行 cout << '|' << setw(4) << a << "|\n"; // 設定輸出長度 4 cout << '|' << setw(6) << a << "|\n"; // 設定輸出長度 6 cout << '|' << left << setw(6) << a << "|\n"; // 設定輸出長度 6 (靠左) cout << fixed << setprecision(5) << f << '\n'; // 輸出到小數點五位 ``` 輸出文字 ```tex 202 | 202| | 202| |202 | 87.54871 ``` ---- ### 條件語句 (if-else) ```cpp if (判斷條件) { // 內容 } else if (判斷條件) { // 內容 } else { // 內容 } ``` ---- ### 迴圈 (loop) while loop ```cpp while (迴圈執行條件) { // 內容 } ``` for loop ```cpp for (初值; 迴圈執行條件; 每次迴圈改變) { // 內容 } ``` ---- ### 一維陣列 ```cpp int arr[8]; // 宣告大小 8 的 int 陣列 arr[0] = 10; // arr 位置 0 存入 10 arr[5] = 20; // arr 位置 5 存入 20 cout << arr[0] << ' ' << arr[5] << '\n'; // 輸出 "10 20" ``` <img src="https://hackmd.io/_uploads/Sy4PDJKqA.png" style="width: 500px"> ---- ### 二維陣列 ```cpp int arr[8][6]; // 宣告一個 8 * 6 的陣列 arr[5][4] = 87; // i=5, j=4 的位置存入 87 arr[2][0] = 2; // i=2, j=0 的位置存入 2 cout << arr[5][4] << '\n'; // 輸出 87 ``` <img src="https://hackmd.io/_uploads/rJyS0aYc0.png" style="width: 500px"> ---- ### 函式 (function) ```cpp // 費波納契數列的遞迴函數 // 函數又稱函式又稱副程式 全取決於怎麼用 int fibb(int n) { // 函式左邊那個是要回傳的資料型態 // 函式右邊小括號裡的式傳入的數字 if (n == 0 || n == 1) return n; return fibb(n - 1) + fibb(n - 2); } int main(){ // 主程式 cout << fibb(10); return 0; } ``` ---- ### 自定義結構 (struct) ```cpp struct Point { // 定義一個 struct double x, y; }; int main() { Point pt = {10, 20}; // 宣告一個 struct cout << pt.x << ' ' << pt.y << '\n'; return 0; } ``` ---- ### End of Files (EOF) 有些題目會要求輸入到測資末尾,也就是 EOF ```cpp int num; while (cin >> num) { // 內容 } ``` ---- ### 輸入 n 筆測資 ```cpp cin >> n; // 輸入 n while (n--) { // 內容 } ``` ---- ### 字串 (string) ```cpp string s; cin >> s; cout << s << '\n'; ``` --- <h2 class="text-center">基本例題講解</h2> ---- ### [10783 - Odd Sum][10783] 給一個區間,算區間內的奇數和 :::spoiler <span class="hint">提示</span> 用迴圈遍歷整個區間就可以了 也可以推公式 只是比較麻煩 ::: [10783]: https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1724 ---- ### [00100 - The 3n + 1 problem][00100] 給一個函數的建構方式 要你要把一個區間所有的答案取最大值並輸出 :::spoiler <span class="hint">提示</span> 取最大、最小值的函數 ```cpp cout << max(57, 89) << '\n'; // 輸出 89 cout << min(57, 89) << '\n'; // 輸出 57 ``` ::: [00100]: https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=36 ---- ### [10908 - Largest Square][10908] 給一個 $m \times n$ 的字元陣列與 $q$ 筆詢問 求某幾點的最大同字元正方形邊長 :::spoiler <span class="hint">提示</span> ```cpp // (r, c) 為中心,只要以點為中心掃描就可以找出答案 for (int j = r - i; j <= r + i; j++) { for (int k = c - i; k <= c + i; k++) { // 判斷是否在範圍內且判斷是否與中心的字元相同 if (!in_range(j, k) || grid[r][c] != grid[j][k]) isTrue = false; } } ``` ::: [10908]: https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1849 ---- ### [11150 - Cola][11150] 買可樂,每當收集到三個空瓶子時,就可以免費換得一瓶新的可樂,問總共可以喝幾瓶可樂 :::spoiler <span class="hint">提示</span> 這一題可以模擬,也可以推公式 ::: [11150]: https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2091 ---- ### [10242 - Fourth Point !!][10242] 給平行四邊形三點座標,找出第四點座標 注意小數點 <!-- .element: class="fragment" data-fragment-index="1" --> [10242]: https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1183 ---- ### [10038 - Jolly Jumpers][10038] 題目定義相鄰兩數差的絕對值恰好為 $1$ ~ $n-1$,就是 jolly jumper,最後要你判斷給的輸入是不是 jolly jumper [10038]: https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=979 ---- ### [11349 - Symmetric Matrix][11349] 判斷一個矩陣是否點對稱 :::spoiler <span class="hint">提示</span> 其實只要把他壓成一維陣列 再判斷是否左右對稱 (迴文) 即可 ::: [11349]: https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2324 ---- ### [10170 - The Hotel with Infinite Rooms][10170] 有一個旅館,裡面有一些奇怪的規定: - 每組都會在早上入住,離開時在晚上離開 - 另一組人會在上一組人離開的後一天入住 - 下一組客人一定會比上一組客人還要多一人 - 當每組有 $n$ 人時,他們會在旅館住 $n$ 天 給你第一天住了 $S$ 人,問第 $D$ 天時旅館住了幾人 :::spoiler <span class="hint">提示</span> 用迴圈模擬或是推公式 ::: [10170]: https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1111 --- 以上是本章內容 [題目連結](https://vjudge.net/contest/653049) <a href="https://github.com/ShanCisgood/cpp_for_uva" style="color: #191919">答案在這裡</a>
{"title":"計畫介紹與 C++ 基礎語法","description":"CPE 檢定介紹","slideOptions":"{\"transition\":\"fade\"}","contributors":"[{\"id\":\"4f67a8cd-06ae-45dc-a8e3-62c6a41e5a37\",\"add\":10792,\"del\":2684},{\"id\":\"dbf3352a-4a61-4739-9e70-396b6f72e250\",\"add\":6716,\"del\":8225}]"}
    601 views
   Owned this note