## 南大附中第二屆資訊研究社 ## NFIRC 2nd ### 第二堂社課 主講:倫敦鐵喬 --- ## [簡單介紹第一堂社課](https://hackmd.io/@NFIRC2nd/SJzlzEOCR) ---- ## 社團事務 - 社費 400元 用於講師費、聚餐等等 有餘額會再回饋給大家 下一次社課可以開始繳費 繳錢後請一定要拿收據 - [資源彙整頁面](https://hackmd.io/@NFIRC2nd/BkHfeCY0A/https%3A%2F%2Fhackmd.io%2F%40NFIRC2nd%2FSJzlzEOCR) - 社服及訂購表單將於下一次社課公布 ---- ## DISCORD 介紹 - username不是顯示名字 e.g. 倫敦鐵喬 - $bone1018$ 則username為 $bone1018$ - 匿名提問版 打上 $/anony$ $send$ 可以自由提問 幹部們看到都會回應 ---- ## Online Judge | OJ | 簡稱 | TIME | | :-- | :-- | :-- | | TOJ | TOJ | 上學期期末賽 | | Zero Judge | ZJ | 社課題單 | 所以現在創一個ZJ帳號並加入課程ㄅ ### 請用自己的gmail ZJ不支援學校帳號 課程代碼 :VnVHAO ---- ## 社群&資源 - [競賽資源壓縮包](https://www.lssh.tp.edu.tw/office/div_800/Qsection_801/information_contest_list/) - [SCIST 南台灣學生資訊社群](https://scist.org/) - [程式獵人](https://www.instagram.com/codehunter_camp?utm_source=ig_web_button_share_sheet&igsh=ZDNlZDc0MzIxNw==) - [TPEC DISCORD](https://discord.gg/b3XmEup5Nz) - [APCS Guide](https://apcs.guide/) - [APCS 模擬測驗團隊](https://apcs-simulation.com/) - [SA 流 C++ 競程修練心法](https://hackmd.io/@sa072686/cp/%2F%40sa072686%2FBkTJ0imPB) <!--整合南台灣的資訊 舉辦營隊 並推動多元課程 包含演算法和資安 目前的S5演算法總召是創社社長--> <!--由二中社長帕尼擔任總召的程式獵人是主打python學習營的資源推廣團體 除了python他們也會不時有合作活動增添課程豐富度例如今年1月與資訊安全講師OsGa的程式獵人二中場--> <!--總召為嘉中社長的TPEC創立初衷是提供程式小白一個可以問問題和整理資源的環境 他們也會拍一些教學影片以及提供資源使資源接收不易的同學能夠得到較完善的資源--> <!-- APCS GUIDE 線上學習apcs的好幫手有非常完善的學習資源目前也在持續更新中如果有覺得社課教太慢了非常想學新東西的同學建議可以上去看看--> <!-- APCS模擬測驗團隊 apcs模擬測驗團隊每個月月底都會舉辦一場模擬測驗他們的宗旨是想協助大家考取apcs檢定--> --- ## 正式上課 ---- ## 編譯器 ![螢幕擷取畫面 2024-10-15 223251](https://hackmd.io/_uploads/H10Eal2kJg.png) ---- 我們社團使用的是 ### Code::blocks - 建立檔案 ``` 點擊左上角File->New->File ``` - 選擇類別 ``` File->C++ ``` - 取名並儲存 ``` 備註 存D槽才不會消失 儲存快捷鍵 Ctrl+S ``` --- ## 基礎架構 ---- ```cpp= #include <bits/stdc++.h> //標頭檔 using namespace std; //命名空間 int main() { //主程式 //Code return 0; //回傳0結束 } ``` <!--如果沒有命名空間的話 每串程式碼都要額外命名--> ---- ## 標頭檔 標頭檔的作用是控制你在主程式能用到的code類型 例如 : iosteam 就是控制輸入輸出 ---- 競程的時候建議用<bits/stdc++.h>萬用標頭檔 <!--因為其他標頭檔實在太多了 例如以下--> ```cpp= #include <iostream> #include <algorithm> #include <bitset> #include <complex> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <typeinfo> #include <utility> #include <valarray> #include <vector> ``` --- ## 小技巧 ---- ### 全英鍵盤 打程式的時候所有標點符號都是英文的 如果你會因為按 shift 不小心切到中文的 可以試著用全英鍵盤 ---- ### 快捷鍵 Ctrl + A 全選 Ctrl + C 複製 Ctrl + V 貼上 || 記法 : AC✅ || --- ## 輸出(output) cout 可以叫他吸奧 功用就是輸出 ---- 假設今天要吸奧***NFIRC 2nd*** Code ``` cout << "NFIRC 2nd.\n"; ``` ---- ## 換行 有些人會用endl換行 但競程比較常用\n ---- 加入基礎架構 ```cpp= include <bits/stdc++.h> using namespace std; int main(){ cout << "NFIRC 2nd.\n"; return 0; } ``` 輸出結果 ```txt NFIRC 2nd. ``` ---- ## 去試試看 ### A003 --- 在教輸入之前我們先來講 ## 變數(variable) 用於儲存數據的命名內定區,需指定類型和名稱(可自己定義) ---- ### 關於變數的定義 1. type:告訴程式這個變數可以儲存什麼樣的資料,例如 int(整數) float(浮點數) 2. name:給這變數一個名字,方便在寫的過程中使用 3. 初始值:你可以在定義時給變數一個初始值 ---- 切記 使用變數之前 ## 一定要先宣告 **宣告方法:型別 變數名稱** ```cpp= int a; string a; int a = 0; ``` --- 接下來就是 ## 輸入(input) ---- cin 吸印 輸出符號為 cin >> 很常會和cout的<<搞混 我自己的記法是 <mark>>> = 箭頭進入</mark> ```cpp= int a, b; cin >> a >> b; ``` ---- ### 讀取整行輸入 ```cpp= string line; // 命名字串 getline(cin, line); // 輸入整句字串 ``` ---- ## 實際範例 讀取用戶姓名和年齡 ```cpp= #include <bits/stdc++.h> using namespace std; int main() { string name; int age; cout << "Enter your name: " << "\n"; cout << "Enter your age: " << "\n"; cin >> age; cout << "Hello, " << name << ". I am " << age << " years old." << "\n"; return 0; } ``` --- ## 我明明照著寫為什麼 WA ### 或許你忘記...? - 忘記加分號 - 字拼錯 - 宣告變數 - cin cout 串接方向寫反 - 括號用錯或沒加 ---- - 忘記加分號 ``` #include <bits/stdc++.h> using namespace std int main() { string s cin >> s cout << "hello, " << s << "\n" return 0 } ``` ---- - 字拼錯 | ❌ | ✅ | |:---------:|:---------:| | incloud | include | | namesapce | namespace | | mian | main | | hollow | hello | | count | cout | | retrun | return | --- ## 四則運算 - 加減乘除( + - * / ) 在 C++ 裡 四則運算大多就跟平常一樣 ``` #include <bits/stdc++.h> using namespace std; int main() { int a = 7, b = 4; cout << "a + b = " << a + b << "\n"; cout << "a - b = " << a - b << "\n"; cout << "a * b = " << a * b << "\n"; return 0; } ``` ---- 執行結果 ``` a + b = 11 a - b = 3 a * b = 28 ``` --- ## 上ZJ練習看看!
{"title":"10/16","description":"基礎環境複習","contributors":"[{\"id\":\"bbf9eb14-e315-44e7-8182-192d5e2a52d5\",\"add\":7157,\"del\":3446},{\"id\":\"9df8c9b4-5deb-4d6a-b446-f799cbce617c\",\"add\":952,\"del\":74},{\"id\":\"a5e01884-520b-4df5-8e23-bfcc32fb4697\",\"add\":215,\"del\":125},{\"id\":\"2da38d67-8839-4956-a1a1-49b787e76295\",\"add\":80,\"del\":59}]"}
    320 views
   Owned this note