Mr.Mow
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    ###### tags: `程設與專案管理` # 111年新尖兵計畫 ─ 程式設計與專案管理 # <font color="#FF79BC">新尖兵課程資源 :speak_no_evil:</font> > See all emoji list here[HackMD表情](https://www.webfx.com/tools/emoji-cheat-sheet/) >> ### [ - 總資源 - ](https://drive.google.com/drive/folders/1KPXoa0c_4XLhexMceodRU1_A38GBl1CC?usp=share_link) - ### 同學檔案 [Google Drive](https://drive.google.com/drive/folders/1QvN4Dgfp_7-WMItb1SC7HplsTmZD7VLP?usp=share_link) - ### 教師資源 [Google Drive](https://drive.google.com/drive/folders/14OwARXrbpwhdJ9P-E8zIO8vYteBy1-Pl) # Tarkus 托可思 程式邏輯 ### Continue print console input ( 2023/01/10 ![](https://i.imgur.com/zZovuND.png) --- ### Print A & B To Get A * B 解1 ( 2023/01/10 ![](https://i.imgur.com/w5FjcZf.png) --- ### ▲▲▲ After Module >> Get A * B (main code) ![](https://i.imgur.com/fEE1B4H.png) #### (module of part A & B) ![](https://i.imgur.com/2g59zFU.png) ![](https://i.imgur.com/j13lrJW.png) ### Return value ![](https://i.imgur.com/twlc92K.png) --- ### Print A & B To Get A * B 解2 ( 2023/01/10 -- by Changyu ![](https://i.imgur.com/5C6Y0cJl.png) ![](https://i.imgur.com/qmuJY74l.png) ![](https://i.imgur.com/H1lJic5l.png) --- ### Guess number ( 2023/01/10 -- by changyu ![](https://i.imgur.com/jw6r95Z.png) --- ### Guess number ( 個位數 & 十位數 比較 ( 2023/01/13 >思路:將答案 和 猜數 的 個位數 & 十位數分別存取,在 main code ![](https://i.imgur.com/nIvywBl.png) answer md 定義答案 ![](https://i.imgur.com/2Wtr5Rb.png) guess md 定義參數 ![](https://i.imgur.com/a0DfNGR.png) vs1 比較十位數 ![](https://i.imgur.com/sxjki33.png) vs2 比較個位數 ![](https://i.imgur.com/F2YKGdp.png) zero 參數歸零 ![](https://i.imgur.com/eoRAr1k.png) guess zero 猜數歸零 ![](https://i.imgur.com/1SpgEjv.png) --- ### 終極密碼 ( 2023/01/13 > #### 思路: | Exam | 所需參數 | 每次輸入參數 | | ------ | ------ | --- | | 第一次猜數:50 輸出結果:0-50 | answer (終極密碼) |1.覆蓋guess | | 第二次猜數:20 輸出結果:20-50| guess (前次輸入,後次輸入) |2.比較答案| | 第一次猜數:38 輸出結果:20-38| min (最小值) & max (最大值) | 3.取代範圍值 | >若後次 guess 大於 answer 取代 max >若後次 guess 小於 answer 取代 min main code ![](7b3YnbP.png) answer part ![](https://i.imgur.com/Rih7ii0.png) 大於答案 ![](https://i.imgur.com/C59pvHc.png) 輸入0繼續 ![](https://i.imgur.com/UJNhVSS.png) 小於答案 ![](https://i.imgur.com/HCaV7SS.png) a值 ![](https://i.imgur.com/2C2UPFR.png) b值 ![](https://i.imgur.com/BMCr80o.png) --- # (WordPress) Website design & manage #### Wordpress 參考yt >> 小犬、帶路姬 ### wordpress 後臺進入 王彥勳 [後臺進入](https://wjmarvin.parasophia.net/lazycat-welcome/) 張簡千郁 [後臺進入](https://changyu.parasophia.net/lucky-girl-web-longin/) -2022/12/23 編輯- [tarkustech](https://tarkustech.com/zh_tw/) 流程圖使用繪圖軟體:[draw.io](https://app.diagrams.net/) 圖庫推薦 - [stocksnap](https://www.shutterstock.com/zh-Hant/explore/taiwan-stock-assets?c3apidt=p70822971621&gclid=EAIaIQobChMI_oCs9IyZ_AIVKtWWCh1azwBIEAAYASAAEgKL-PD_BwE&gclsrc=aw.ds&kw=stock%20photo%20website) - [pixabay](https://pixabay.com/) (free) - [pexels](https://www.pexels.com/zh-tw/) (free) 可編輯圖片設計 - [patternico](https://patternico.com/) - [Subtle pattern](https://www.toptal.com/designers/subtlepatterns/?adnetwork=search&keyword=toptal%20pattern&creative=354748341567&campaignid=1592880893&adgroupid=64417985961&matchtype=e&network=g&device=c&devicemodel=&adposition=&noun=&gclid=EAIaIQobChMInO2r442Z_AIVUa2WCh0kng6PEAAYASAAEgIbB_D_BwE) 參考資料:[2022 10大網頁製作平台推薦](https://deanlife.blog/web-design-platforms-recommend/) 參考關鍵字:wix、weebly、strikingly、webnode、webflow、wordpres_.org、wordpress_com、manaferra wprdpress (上課所說 wordpress 指的是 ==wordpress.org==) ### 文章目錄索引 外掛: - easy table of content - Q2W3 Fixed Widget for wordpress - chained quiz. (branching logic) >> 問卷相關掛外 - Contact 7 / wpform (表格類外掛) - WPS Hide Login 更改登入後台網址 ( 資安 ![](https://i.imgur.com/4mrEFOSm.png) - UpdraftPlus - Backup/Restore >> 備份 ![](https://i.imgur.com/TItEwBJm.png) ----- 一頁式 Langing page (著陸頁) -- KeyWord:[scrooser](https://www.scrooser.com/en/) / [agnes-b](https://reurl.cc/Z1q3b3) / [Thermomug](https://thermomug.com/) / [PHC](https://www.phchd.com/global) / [The eddy nyc](https://www.theeddynyc.com/) / [Dyson360](https://reurl.cc/ROEGvg) / [jetedge](https://www.flyjetedge.com/) / ## A.張簡千郁 - 題目領域:毛小孩 - 參考網頁:[好味小姐-好味商店](https://www.ladyflavor.com/?gclid=Cj0KCQiAwJWdBhCYARIsAJc4idCrdbQxZHDI_E-ul9Ppwcn09xHY_EonkbO-0ivn6jYsVH-6RdORjU8aAje4EALw_wcB) ## B.王彥勳 - 題目領域:餐飲 - 參考網頁:[noma](https://noma.dk/) - 參考資料:[2021世界最佳50餐廳](https://www.vogue.com.tw/lifestyle/article/noma-the-worlds-50-best-restaurants-2021) ----- 網域服務商:網域代管商是專門為您管理網域名稱(例如<貴機構網域>.com) 的網際網路服務供應商,他們會使用網域名稱系統(DNS) 記錄將您的網域名稱與電子郵件服務、網站及其他網路服務建立連結。 常見的網域代管商包括GoDaddy、enom、DreamHost 和1&1 IONOS 等。 網域是否可用&購買:[GoDaddy](https://tw.godaddy.com/?checkAvail=1&tmskey=1dom_03_all_20spin) / [namecheap](https://www.namecheap.com/?gclid=Cj0KCQiAwJWdBhCYARIsAJc4idDBf3Ke3ayvQ-3V0rSrvGU5G0560qO2q71Hshbj-zbPOzYDeGMbFy4aAmWoEALw_wcB) ----- Keyword:[Bluehost](https://reurl.cc/ROEMen) / [A2 hosting](https://reurl.cc/6LYzjk) / Traffic 引流 / 網站後台製作NAS(不建議,除非是很厲害的工程師) # 專案管理 :nerd_face: - ### 如何用價值主張圖真正了解你的顧客... [WebSite](https://reurl.cc/06lN8x) - 專案題目:機車行車紀錄器 -參考資料:嘖嘖-[雙頭行車紀錄器](https://www.zeczec.com/projects/mufu-v20s) / 蝦皮-[安全帽行車紀錄氣](https://reurl.cc/WqM96x) 安規實驗室:[Intertek](https://www.intertek-twn.com/FrontEnd/default.aspx) EX:評估-測試-取得證書 ### 專案的五大流程 ![](https://i.imgur.com/Bvz2v7x.png) ### About 開發成本 藍色段 >> 產品生命週期 (開發成本) 營運成本:製作成本30%、行銷成本30%、營運成本30%、稅&手續費10% 營運成本先訂定價 > 製作成本 除 0.3 會落在價格區間 執行、監控:進度(時間) / 錢(成本) / 品質(規範) ![](https://i.imgur.com/GhVa1Fs.png) ![](https://i.imgur.com/jIITthW.png) ### About 定價 ![](https://i.imgur.com/dwIvpti.jpg) ![](https://i.imgur.com/JhOV52Z.jpg) ### 定價 & 成本 的關係與算法 ![](https://i.imgur.com/3e1mcMp.jpg) - 若定價未知:先網上查詢參考價 EX:$3000為例,3000*0.3 約 1000,則$1000為製作成本 以行車紀錄器為主題,我方提供雲服務方面要開單一帳號的成本$100,故為$1100 再以 $1100 / 0.3 = $3666 此為我方定價 $3666 * 1.3 = $4766 為終端建議售價,則3666 至 4766 為價格把控區間 ![](https://i.imgur.com/SUVr5oAm.jpg) EX:$3666為 "早鳥價",按照時間和層級最終還原為市價。 而早鳥價過時候,則 $3666 為經銷商價 (拿到經銷價條件比如賣至一定累積金額或個數) ### 補充:跨國定價算法 ※若生產地不同,會影響製作成本的高低;銷售地不是本國的話會讓運費和關稅的價格提高 > [ 製作成本 + 運費 + 關稅 ] / 0.3 = 跨國定價 ![][(https://i.imgur.com/6iFzSGl.jpg) - 分析市場價值:價 * 數/年 ### About 直接成本 & 間接成本 - 直接成本:跟賺錢(收費)有直接關係的 EX:撞球店若有人開桌才會開燈, A.10W水電 B.10W人事 C.10W租金 代表開燈時即有賺錢,所以水電為直接成本,嚴謹點的話 >> 指的是電燈的費用,而人事和租金在不賺錢時也一直消耗著,所以人事和租金為間接成本 撞球店收費:$2.5 /分/桌 店內有47桌,營業時間為:10am to 7am 產值:$2.5 * 60(min>hr) * 21(營業時間) * 30(月天) * 47(桌數) = $4441500 --- ![](https://i.imgur.com/ZTexyY9.png) --- ## Arduino ### [軟體下載安裝](https://www.arduino.cc/en/software) // [上課參考講義](https://reurl.cc/lZmL2E)// [Arduino 程式語法](https://reurl.cc/YdgloO) ### Arduino 軟體起始設定 ![](https://i.imgur.com/cUeGo9J.png) 接上主機板後,從裝置管理員確認要選擇的COM ![](https://i.imgur.com/zJH3TBC.png) ![](https://i.imgur.com/wqv5VcY.png) ![](https://i.imgur.com/xgv5LC1.png) --- ### 4個 led燈 同時閃爍 ![](https://i.imgur.com/gq3Me6z.png) --- ### 4個 led燈 依序亮起(前燈不滅) 然後暗掉/ 循環 ![](https://i.imgur.com/oBMPj4v.png) --- ### 4個 led燈 依序亮起(前燈滅) 然後暗掉/循環 ![](https://i.imgur.com/A9n0k9N.png) --- ### 4個 led燈 暗 > 半亮 > 亮 三個 去 循環 ![](https://i.imgur.com/j8bKzXK.png) --- ### 4個 led燈 暗 > 半亮 > 亮 > 半亮 > 暗 循環後 ![](https://i.imgur.com/ywXBgk2.png) --- ![](https://i.imgur.com/Zi85t6J.png) --- ### 單一led呼吸燈跑完後遞增循環 ![](https://i.imgur.com/I1b4bGZ.png) #### 程式解二 ![](https://i.imgur.com/hI6biwp.png) --- ### 矩陣 --2023/01/11 ![](https://i.imgur.com/3DIj3vh.png) ![](https://i.imgur.com/gt7pJCn.png) ### 矩陣應用題目 --2023/01/11 ![](https://i.imgur.com/pCMVATS.png) #### 矩陣題目解 --2023/01/11 ![](https://i.imgur.com/I71n53U.png) --- ### 蠟燭燈 --2023/01/11 ![](https://i.imgur.com/VGthmvE.png) --- ### 結合距離感測器後 的語法 ![](https://i.imgur.com/lo21icg.png) ### [下方回饋距離感測數值](https://i.imgur.com/IP6sR6J.png) ```c= const byte TrigPin = 35; const int EchoPin = 34; float Time_Value; float CM_Value; void setup() { // put your setup code here, to run once: Serial.begin(9600); pinMode(TrigPin,OUTPUT); pinMode(EchoPin,INPUT); } void loop() { // put your main code here, to run repeatedly: digitalWrite(TrigPin,LOW); delayMicroseconds(5); digitalWrite(TrigPin,HIGH); delayMicroseconds(10); digitalWrite(TrigPin,LOW); Time_Value=pulseIn(EchoPin,HIGH); CM_Value=Time_Value/29/2; Serial.println(CM_Value); delay(100); } ``` ---- ### [Arduino 控制馬達 2023/01/12](https://i.imgur.com/9FyC0j9.png) ```c= void setup() { // put your setup code here, to run once: pinMode(38,OUTPUT); pinMode(39,OUTPUT); pinMode(40,OUTPUT); pinMode(41,OUTPUT); } void loop() { // put your main code here, to run repeatedly: analogWrite(2,255); //speed digitalWrite(38,HIGH); digitalWrite(39,LOW); analogWrite(3,255); //speed digitalWrite(40,HIGH); digitalWrite(41,LOW); delay(1000); } ``` ### [Arduino 控制馬達 優化01 2023/01/12](https://i.imgur.com/MCEMNBu.png) ```c= int speed; void forward(int a){ analogWrite(2,speed); //speed digitalWrite(38,HIGH); digitalWrite(39,LOW); analogWrite(3,speed); //speed digitalWrite(40,HIGH); digitalWrite(41,LOW); delay(a*1000); } void setup() { // put your setup code here, to run once: pinMode(38,OUTPUT); pinMode(39,OUTPUT); pinMode(40,OUTPUT); pinMode(41,OUTPUT); } void loop() { // put your main code here, to run repeatedly: speed=100; forward(10); delay(500); speed=0; forward(10); } ``` ### [Arduino 透過輸入數值"1" 控制馬達運轉 "前進&停止" 2023/01/12](https://i.imgur.com/85mZaCW.png) ```c= int speed; void forward(int a){ analogWrite(2,speed); //speed digitalWrite(38,HIGH); digitalWrite(39,LOW); analogWrite(3,speed); //speed digitalWrite(40,HIGH); digitalWrite(41,LOW); delay(a*100); } void setup() { // put your setup code here, to run once: pinMode(38,OUTPUT); pinMode(39,OUTPUT); pinMode(40,OUTPUT); pinMode(41,OUTPUT); Serial.begin(9600); } void loop() { // put your main code here, to run repeatedly: if (Serial.available()){ int cmd=Serial.parseInt(); if (cmd==1){ speed=100; forward(10); speed=0; forward(10); } else{ speed=0; forward(10); } } } ``` ### [Arduino 透過輸入數值 控制馬達 "倒退 Part" 2023/01/12](https://i.imgur.com/85mZaCW.png) ```c= //設定的Part void backward(int b){ analogWrite(2,speed); //speed digitalWrite(38,LOW); digitalWrite(39,HIGH); analogWrite(3,speed); //speed digitalWrite(40,LOW); digitalWrite(41,HIGH); delay(b*50); } //判斷式的Part void loop() { // put your main code here, to run repeatedly: if (Serial.available()){ int cmd=Serial.parseInt(); //前進 if (cmd==1){ speed=100; forward(10); speed=0; forward(10); } //後退 if (cmd==2){ speed=100; backward(10); speed=0; backward(10); } //暫停 else{ speed=0; forward(10); } } } ``` ### [Arduino 透過距離感測器回饋數值控制 馬達轉速 2023/01/12](https://i.imgur.com/4Iy2rfl.png) ```c= int speed; const byte TrigPin = 35; const int EchoPin = 34; float Time_Value; float CM_Value; void forward(int a){ analogWrite(2,speed); //speed digitalWrite(38,HIGH); digitalWrite(39,LOW); analogWrite(3,speed); //speed digitalWrite(40,HIGH); digitalWrite(41,LOW); } void backward(int b){ analogWrite(2,speed); //speed digitalWrite(38,LOW); digitalWrite(39,HIGH); analogWrite(3,speed); //speed digitalWrite(40,LOW); digitalWrite(41,HIGH); } void setup() { // put your setup code here, to run once: pinMode(38,OUTPUT); pinMode(39,OUTPUT); pinMode(40,OUTPUT); pinMode(41,OUTPUT); Serial.begin(9600); pinMode(TrigPin,OUTPUT); pinMode(EchoPin,INPUT); } void loop() { // put your main code here, to run repeatedly: //距離感測回饋 digitalWrite(TrigPin,LOW); delayMicroseconds(5); digitalWrite(TrigPin,HIGH); delayMicroseconds(10); digitalWrite(TrigPin,LOW); Time_Value=pulseIn(EchoPin,HIGH); CM_Value=Time_Value/29/2; Serial.println(CM_Value); delay(500); //距離躍進,速度越慢 ; 距離越遠,速度越快 speed=CM_Value; forward(1); } ``` ### Arduino 電路板 ![](https://i.imgur.com/g7ijg7r.png) ### Arduino 資料型態 ![](https://i.imgur.com/Myp8n7b.png) ### Arduino 藍芽控制 ```c= int lspd; int rspd; int up; int mode; //前進參數設定 void forward(int a){ analogWrite(2,lspd); //speed digitalWrite(38,HIGH); digitalWrite(39,LOW); analogWrite(3,rspd); //speed digitalWrite(40,HIGH); digitalWrite(41,LOW); delay(a*100); } //後退參數設定 void backward(int b){ analogWrite(2,lspd); //speed digitalWrite(38,LOW); digitalWrite(39,HIGH); analogWrite(3,rspd); //speed digitalWrite(40,LOW); digitalWrite(41,HIGH); delay(b*100); } //面對距離感測器的左邊車速 void leftward(int c){ analogWrite(2,lspd); //speed digitalWrite(38,HIGH); digitalWrite(39,LOW); delay(c*100); } //面對距離感測器的右邊車速 void rightward(int d){ analogWrite(3,rspd); //speed digitalWrite(38,HIGH); digitalWrite(39,LOW); delay(d*100); } //車速設定覆蓋 void speed(int z){ rspd=z; lspd=z; } void a_push(){ rspd=rspd+25; lspd=lspd+25; Serial.println(rspd); delay(50); } void b_push(){ rspd=rspd-25; lspd=lspd-25; Serial.println(rspd); delay(50); } //左轉(前進) void left(){ speed(100); leftward(10); speed(0); leftward(2); } //右轉(後退) void right(){ speed(100); rightward(10); speed(0); rightward(2); } //停止 void stop(){ speed(0); rightward(2); leftward(2); } void setup() { // put your setup c pinMode(38,OUTPUT); pinMode(39,OUTPUT); pinMode(40,OUTPUT); pinMode(41,OUTPUT);//de here, to run once: Serial3.begin(57600); Serial.begin(9600); } void loop() { // put your main code here, to run repeatedly: if (Serial3.available()){ char cmd = Serial3.read(); //讀取藍芽針腳收到的信號 Serial.println(cmd); switch (cmd){ if (rspd>0){ //前進的過程中,用A來控制加速 case 'A': a_push(); break; //前進的過程中,用B來控制減速 case 'B': b_push(); break; } if (rspd<0){ speed(25); //後退的過程中,用A來控制減速 case 'A': b_push(); break; //後退的過程中,用B來控制加速 case 'B': a_push(); break; } //left case 'C': left(); break; //right case 'D': right(); break; } } delay(50); } ``` ### 跟車/車距恆定值/距離加.加速/距離減.減速 <font size=5>關於感測參數設定相關原理 & 詳解</font> ![](https://i.imgur.com/CAj7M4N.png) code line 67-71 ![](https://i.imgur.com/F7X5eF1.png) ```c= int lspd; int rspd; int up; int mode; int length; const int TrigPin = 35; //指定發射端的針腳(Pin腳) const int EchoPin = 34; float Time_Value; float CM_Value; //面對距離感測器的左邊車速 void leftward(int c){ analogWrite(2,lspd); //speed // 真值表:跟馬達控制板L298N 相搭配的真值表,不同控制表的真值表其內容不一樣 //HIGH 跟 LOW 相互搭配,形成前進跟後退的功能 //H + L 前進 //L + H 後退 //H + H 停下(煞停) //L + L 停下(緩停) digitalWrite(38,HIGH); digitalWrite(39,LOW); delay(c*100); } //面對距離感測器的右邊車速 void rightward(int d){ analogWrite(3,rspd); //speed digitalWrite(38,HIGH); digitalWrite(39,LOW); delay(d*100); } //車速設定覆蓋 void speed(int z){ rspd=z; lspd=z; rightward(10); leftward(10); } void a_push(int a){ speed(a); Serial.println(rspd); delay(50); } //停止 void stop(){ speed(0); rightward(2); leftward(2); } void setup() { // put your setup c pinMode(38,OUTPUT); pinMode(39,OUTPUT); pinMode(40,OUTPUT); pinMode(41,OUTPUT);//de here, to run once: Serial3.begin(57600); Serial.begin(9600); pinMode(TrigPin,OUTPUT); pinMode(EchoPin,INPUT); } void loop() { // put your main code here, to run repeatedly: //距離感測回饋值 digitalWrite(TrigPin,LOW); //確定訊號發射端一開使為關閉狀態 delayMicroseconds(5); digitalWrite(TrigPin,HIGH); //將發射端的狀態 "打開" 10%秒 delayMicroseconds(10); digitalWrite(TrigPin,LOW); // 訊號端發射完訊號後,將狀態確定為 LOW模式 Time_Value=pulseIn(EchoPin,HIGH); //量測多久之後會收到回撥的脈衝訊號 //藉由上一行量測到的時間,算出感測器跟障礙物間距離 //距離 = (速度 * 時間) / 2 //海平面上,聲音的速率大約343 m/s,因此走完每花了約29分之一秒 //CM_Value(距離)=Time_Value(量測到的時間) 乘 超音波感測器的速度(也就是 / 29) ,再 / 2 CM_Value=Time_Value/29/2; Serial.println(CM_Value); delay(20); //距離躍進,速度越慢 ; 距離越遠,速度越快 length=CM_Value; //距離恆定,車速恆定 if (length>30 and length<35){ a_push(100); } //距離拉大,車速加速 if (length>35){ a_push(200); } //距離減小,車速減速 if (length<30){ a_push(60); } //停車 if (length<15){ stop(); } } ``` # 職場談論 - 主旨 - 根據甚麼樣的人或是 - 想表達的目標 - 希望對方做甚麼/提供甚麼 - 是否有時間/地點的限制 ## 活用職場文書 Part ### 被指派跟人,遭放生 #### 角色:主管、A君(公司老人、前輩、比你早進公司之人) 新工作就職後,進公司後被主管指派跟著A君做事,但對方不理,即便主動接觸,仍各種推託,一星期後被主管告知 不適任此項工作 ==如何自保== 用信箱向A君詢問工作內容或可做事項,向主管發送副本回復工作指派內容回饋 (主旨:我是XXX,新人報到第一天工作內容指派事項//內容以條列式為主),同時留下工作日誌(今日完成、代辦事項、明日目標) >向主管報告只是第一天,當日及以後可活用收件者&副本 >※收件者和副本都可看到信件內容,但可以從這之中看出職階地位的差異 <p> </p> <p> </p> ### 單獨告知工作內容 A君於會議室單獨(或其他情境之下),告知將要進行的專案進度或分配的工作內容 ==留下紀錄== 可發信件告知專案組或合作人員自己將要負責的工作內容/將今日談話內容條列式整理,以收件人為A君、副本為主管的方式發送信件 > 會議紀錄可助你後續追蹤 > 若要將當事人參與的談話紀錄發給第三方,可先告知當事人(為了發而發) > 若被拒,委婉點:我待會將專案的重點整理一下發給你、CC主管(CC指副本),讓主管知道進度可以嗎? <p> </p> ==記錄&電話確認== > 若需要跨部門聯絡,也建議先發信件,兩分鐘左右後打電話告知(確認) > 遇到急事,可先電話後信件 >> <font color="#FF79BC">先後順序可調,但該有要有</font> <p> </p> ==延伸:追蹤進度的方式== >1.請問這件事情好了嗎?可不可以回報給我 2.請問這件事情好了嗎?可不可以回報給我,我主管需要回我回報 3.會議紀錄(白紙黑字) & 我主管在要(代表公事) <p> </p> <p> </p> ### 寄信後 仍被害 做好信件防守後還是被主管告知 工作不適任 ==如何自保==  談話完後..用會議路的方式丟問題給主管 ▼ Email txt ▼ 如同剛剛跟主管討稐,我不適任的原因有哪些... 以上有任何不正確的地方請主管幫忙指證 依照我在這段時間所做的紀錄和工作日報,請問裡面有我不適任的原因嗎 ### <font color="#FF79BC">總結:說故事的能力</font> - 1.目的性切入角度 - 2.敘事的邏輯>說話的內容 - 3.關鍵字/必要資訊 --- <p> </p> ## Email Part ### 被委託調查部門的通訊錄 今天主管要你寫一封email,調查部門內部的通訊錄 ==應對方式== - 先問清問題細節 - 請問主管過去有沒有過去通訊錄的範本或紀錄,我要找誰要最快 (如果沒有紀錄資料,主動遞交格式詢問指教) - 請問主管何時需要 - 了解完成這件事情後需要完成的動作 - 找紀錄 (在主管表示找B君後,跟B君接觸) 跟B君互相一下,發信件給B君 CC主管 - 尚方寶劍 寄信告知部門人員今早收到主管交辦任務,須調查通訊錄 --- <p> </p> ## 溝通 Part (平行與跨部門溝通) - 重要性 - 頻率 > 對一個人一天不要超過三封信件 若對主管亦天高過8次溝通 >> 1.延時 2.合併事項 <p> </p> ### 上司的佈達 消防演習 今天主管要你傳達對隊部門內部每個人要傳達的訊息 今天下午3點要進行消防演習,請你對部門進行傳達,同時跟總務部門進行確認 ==應對方式== > 思路 >> 主管為何知道?是否有Email? 詢問主管 請問這件事情是否有信件,能不能轉給我? > > <font color="#FF79BC" size=3>※在向主管詢問時,建議3題內問清楚</font> - 是否有信件可看 - 確認消防演習要做的具體內容 - 如果沒有信件 > 可詢問或查詢是否有過去紀錄資料 - 再次跟總務對街窗口確認 <font color="#FF79BC" size=5>源頭來自於哪裡 為何主管要跟我說這件事情 主管預期我要做出甚麼反映</font> <p> </p> ### 上司的佈達 尾牙 上司告知你今晚6點尾牙 1. 沒告知地點 先問地點 → 老闆,地點決定了嗎/是不是我要訂好了再跟大家說 (拋磚引玉,用意不再詢問地點,而是告知老闆少傳達訊息) > 通常主管要你去佈達的事項通常是因為缺少或需要確認甚麼事項 <p> </p> ### <font color="#FF79BC">總結:說故事的能力</font> - 1.用目標決定你的說話技巧,若沒有達到目標,試著想為麼沒有做到 - 2.台風 > 敘事的邏輯 > 說話的內容 <p> </p> ## 稱讚 Part 稱讚來源不同: 副總的稱讚 (需要謹慎思考,是否需要你做甚麼事情,源頭為何) 同事的稱讚 (有求於你) 危險 >> 帶你的人跟你的直屬上司以外的高職階的人稱讚 解 >> 轉移:根據老闆的指示,跟老闆學習的結果 <p> </p> ## 自我價值 > <font size=6>**晴天送傘,雨天收傘:建立自我價值**</font> > 延伸思考問題:我在別人眼中會促成甚麼利用價值 <p> </p> ## 面試談論思考 <font size=4>**在面試中如何透過問題或問的方式了解到自己的工作環境**</font> > 主管我想確認一下,這個職缺,你開出來是在未來有甚麼規劃,希望達成甚麼事情? > 關鍵點 ==1.前人為何走== ==2.是否為新職缺== <font size=4>**About 此職位前人為何而走**</font> - 家裡有事 → 裡面的人太機掰 - 身體不好 → 裡面壓迫感太重 - 搬家 → 這份工作沒有前景 <font size=4>**About 是否為新職缺**</font> - 這個東西在先前有同事做過相關的文件 & 內容,你來是接手或完成相關事項等等.. → 接攤子 - 這個部門是新的規劃... → 新職缺 - 你進來之後再說.. - 1.壓根不會用你 - 2.這個職缺有內情 >若錄取想推 >> 因為家中有事,如果貴公司能等我一個月那再說 <p> </p> # C語言程式基礎 :skull: [C++ 基礎程式參考講義](https://reurl.cc/28dmZE) 大概是八年前的教材 C 語言 文件 標頭檔 關鍵字 ---> stdio.h、random、iostream Linux 筆記 Google關鍵字 ---> "鳥哥" About Python 編譯器 ---> Anaconda [程式線上編譯器](https://www.onlinegdb.com/) [練習題庫](https://zerojudge.tw/) [C面試考題](https://hackmd.io/@a110605/By6DscbVM?type=view) [ C++教學系列 Class](https://hackmd.io/@Mes/MinerT_Class#-C%E6%95%99%E5%AD%B8%E7%B3%BB%E5%88%97-Class) [職業 技能樹](https://roadmap.sh/) 全端工程師[學習地圖(通用 + 前端)](https://reurl.cc/85gppj) 基礎程設 Python [範例試卷](https://reurl.cc/rZ7RRk) [pip install ](http://alex9ufoexploer.blogspot.com/2017/10/python-pip.html) [7個Python使用BeautifulSoup開發網頁爬蟲的實用技巧](https://www.learncodewithmike.com/2020/02/python-beautifulsoup-web-scraper.html) 2022/12/19 基礎程式設計 問答摘要: ### Q1. 怎樣的程度可以找程式相關工作 ?   :eyes: 以正職來說, 至少要能半精通一種語言才比較好在職位上正常運作. ### Q2. 要挑什麼語言開始較佳? 都可以, 以大部分工程師來說,會先將C/C++學習一階段, 理解基本程式運作以後, 做一些小專案後, 再去適應第二種語言. 老師的學習方向 C++ ->python(深度學習課使用) -> java ## 建議大家將程式當作一個可以加速作業的技能,而不是吃飯的飯碗, 加上有些東西會有數學的坎, 想當飯碗要磨練一陣子 寫程式是說話, 專案只是日記, 開發者的話是小說家, 幾乎每天都要有一些產出, 以正規資工系的訓練為例: > 計算機概論 -> 物件導向 -> 演算法 -> 作業系統 資料結構 (有個咚咚叫做STL但我不太記得他的歸類 & 哪一年學到的) .....真的是挺多的, 短時間內難以速成 > 前端 (UI/UX 工程師(設計)) >>> 中端 >>> 後端 (SQL C#,資料庫) * 以職業為例, 如果你是財金系, 懂一點python 或 R 可以整理資料、歸納出報表與儀表板、大數據分析, 加薪會還蠻有感的(至少前幾年是這樣啦) ### Q3.How to start? 先從簡單的概念開始, 慢慢消化50行內的程式例題, 快的話三個月會有起色, 敝人我資質駑鈍, 半年才感受到.... 範例要自己打, 我這堂課不太會出作業, 沒有驗收問題, 但是有打對於你的理解會有幫助 ## 觀念 - ### 運算元 可以變動的數字或文字, 切割記憶體當中的一部分區域做"配置", 配置的記憶體位址 (1) 位址(地址): 0x0000001 (2) 名稱 (3) 資料型態(值) 3.3.1 int, float, char, string, bool (4) 作用範圍: 全域/區域 (5) 延伸: call by....... 生命週期 (可以砍掉該變數使用的記憶體區) 溢位 補數 About call by value/reference:[說明參考](https://bit.ly/2Wn7dxN) 位址.變數名稱. 變數值的關係可參考:[參考資料](https://kopu.chat/c%E8%AA%9E%E8%A8%80-%E8%B6%85%E5%A5%BD%E6%87%82%E7%9A%84%E6%8C%87%E6%A8%99%EF%BC%8C%E5%88%9D%E5%AD%B8%E8%80%85%E8%AB%8B%E9%80%B2%EF%BD%9E/) ### 語法 -- 輸入與輸出 >> cout << 右到左儲存 cin >> 左到右儲存 >> >> ==多個變數可以逗號區隔== >> >> scanf("%d", &a) printf("%s",b) format - ### 運算子 一元、二元、三元(!)(回傳布林值) 算數 %, ++, -- == 比對兩邊是否一樣 3==2 ->F(0) 邏輯匝 != - ### 結構 循序, 選擇, 迴圈 ->迭代,遞迴 - ### 選擇結構 如果下雨, 就不要帶傘 if (下雨){ 不帶傘 } 如果下雨, 就要帶傘;如果不下雨, 就不要帶傘 if (下雨){ 帶傘 } else{ 不帶傘 } #### [流程圖的應用參考範例](https://aprilyang.home.blog/2020/01/08/make-a-simple-cpp-shooting-game/) ----- 20221226 ![](https://i.imgur.com/ZiUS9sa.png) ![](https://i.imgur.com/XpxZtwM.png) 線上講義 3.5.4/3.5.4 3.7.4 判斷質數 ![](https://i.imgur.com/5hZ1G9J.png) -- 3.7.4 老師解法: ![](https://i.imgur.com/Bzlhjl2.png) 巢狀可思考思路 >> 男女結婚年齡分類 1.先分性別 2.男女適婚年齡 ## 4.3 閏年判斷 ![](https://i.imgur.com/vcehxlR.png) ![](https://i.imgur.com/M0BRO8k.png) 巢狀式寫法 ![](https://i.imgur.com/IyhC58H.png) ## 3.4.5 位數算法 ![](https://i.imgur.com/ZYOWAbf.png) ![](https://i.imgur.com/RJ24b34.png) ![](https://i.imgur.com/0lxyvam.png) ## 5.4.2 米字星號金字塔 ![](https://i.imgur.com/lPso3A8.png) ![](https://i.imgur.com/s9cgNKd.png) ## Bubble sort 氣泡排序 [參考資料](https://www.geeksforgeeks.org/bubble-sort/) 優先參考C語言 ![](https://i.imgur.com/wHOfJtN.png) 參考資料範例 ```c= // C program for implementation of Bubble sort #include <stdio.h> void swap(int* xp, int* yp) { int temp = *xp; *xp = *yp; *yp = temp; } // A function to implement bubble sort void bubbleSort(int arr[], int n) { int i, j; for (i = 0; i < n - 1; i++) // Last i elements are already in place for (j = 0; j < n - i - 1; j++) if (arr[j] > arr[j + 1]) swap(&arr[j], &arr[j + 1]); } /* Function to print an array */ void printArray(int arr[], int size) { int i; for (i = 0; i < size; i++) printf("%d ", arr[i]); printf("\n"); } // Driver program to test above functions int main() { int arr[] = { 5, 1, 4, 2, 8 }; int n = sizeof(arr) / sizeof(arr[0]); bubbleSort(arr, n); printf("Sorted array: \n"); printArray(arr, n); return 0; } ``` 2023/01/16 TQC 好考證照: 1.網頁資料擷取與分析 2.基礎程式語言 ※符合條件k=0 Or k=n 才納入計算 ![](https://i.imgur.com/FiW5KQW.png) ※若不整除,n 要一直加下去,直到K(3) 先 n+1 在停止,所以是加兩次 K(0) 到 K(4)一個規律循環,100除4 >> 25個循環,每個循環的n值總和為25,25 * 100 = 250 ![](https://i.imgur.com/HhVcgP1.png) <p> </p> ## 等差或等比數列填空練習。 - 填空練習的要求是:已知數列的前四項,填出第五項。因 為已經知道這些數列只可能是==等差或等比數列==,她決定寫一個程式來完成這些練習。 輸入說明: - 第一行是數列的數目t(0 <= t <= 20)。 - 以下每行均包含四個整數,表示數列的前四項。 - 約定數列的前五項均為不大於105的自然數,等比數列的比值也是自然數。 輸出說明: - 對輸入的每個數列,輸出它的前五項。 ```c= ## //解法A// ## #include <iostream> using namespace std; int main() { int a1=0, a2=0, a3=0, a4=0, C=0; //C為題目數 //for(輸入題目數;題目數的範圍;讓迴圈執行次數等於題目數) for(cin>>C; C>0&&C<=20; C=C-1) { cin >> a1 >> a2 >> a3 >> a4; //輸入數列前四個數 if((a3-a2)==(a2-a1)) //如果這數列為等差數列,則 cout << a1 << " " << a2 << " " << a3 << " " << a4 << " " << a4+(a2-a1) << endl; else //不然就是等比,所以 cout << a1 << " " << a2 << " " << a3 << " " << a4 << " " << a4*(a2/a1) << endl; } return 0; } ## //解法B// ## include<stdio.h> using namespace std; int main(){ int num[20][5] ; int array ; scanf("%d",&array) ; // 看有多少數列後先讀進所有數列 for (int i = 0;i<array;i++){ for (int j=0;j<4;j++){ scanf("%d",&num[i][j]); } } // 逐一處理所有數列 for (int i=0;i<array;i++){ if(num[i][1]-num[i][0]==num[i][2]-num[i][1]){ num[i][4]=num[i][3]+num[i][3]-num[i][2] ; } else { num[i][4]=num[i][3]*num[i][3]/num[i][2] ; } // 印出所有數列 for(int j = 0;j<5;j++){ printf("%d ",num[i][j]); } printf("\n"); } return 0 ; } ``` ## 矩陣的翻轉 已知一(m x n)矩陣A,我們常常需要用到另一個將A中之行與列調換的矩陣。這個動作叫做矩陣的翻轉。 - 輸入說明:第一行會有兩個數字,分別為 列(row)<100 和 行(column)<100,緊接著就是這個矩陣的內容 - 輸出說明:直接輸出翻轉後的矩陣 ※ a[i][j] >> a[列][行] | 第一行//第一列 | 第二列 | 第三列 | | -------- | --------- | --------- | | 第二行//第一列 | 第二列 | 第三列 | ![](https://i.imgur.com/c2UoJfW.png) ```C= //解法 //C++ language //solution link(含註解): #include<iostream> #include<vector> using namespace std; int main(){ int r,c; while(cin>>r>>c){ vector<vector<int>>matrix(105,vector<int>(105)); for(int i=0;i<r;i++){ for(int j=0;j<c;j++){ cin>>matrix[i][j]; } } for(int i=0;i<c;i++){ for(int j=0;j<r;j++){ cout<<matrix[j][i]<<" "; //注意是 [j][i] 不是 [i][j] ! } cout<<"\n"; } } return 0; } ``` ## Python 練習 ![](https://i.imgur.com/KXgeTXD.png) ![](https://i.imgur.com/GnQtaDA.png) ```python= #解法 1 a=int(input('your stary:')) b=int(input('your final:')) Sum=0 for x in range(a,b+1): if(x % 2 == 0): Sum+=x print(Sum) ``` ```python= #解法 2 ( 判斷 & While 迴圈) a=int(input('輸入一個數(a<b)')) b=int(input('輸入一個數')) c=0 if a%2==0: while a<=b: c=c+a a=a+2 print(a) else: a+=1 while a<=b: c=c+a a=a+2 print(a) print(c) ``` ```python= #解法 3 (陣列) a = int(input('請輸入a:')) b = int(input('b:')) L = list(range(a,b+1)) listSum = 0 for number in L: if(number%2==0): listSum += number print(f"Sum of list -> {listSum}") ``` ```python= #解法 4 (變數4) print('請輸入a值及b值,且a<b') a=int(input('a=')) b=int(input('b=')) c=0 t=0 for x in range (a,b,2): if(a%2==0): c+=2 else: a+=1 c+=2 print(c) t=t+c print(t) ``` ## 秘密差 ![](https://i.imgur.com/xhEfRiW.png) ![](https://i.imgur.com/R3Ouzg3.png) ![](https://i.imgur.com/I5lMdMA.png) ```c= //C++解法// #include <iostream> #include <stdio.h> #include <stdlib.h> #include <string.h> using namespace std; int main() { /*在C語言只有char儲存自原,所以用陣列去儲存字串*/ char x[1000]; //輸入數值,1000代表可輸入1000個數字 // "%s" 字串 /*scanf 輸入 same with "input"*/ scanf("%s",x); //讓使用者輸入數值,可理解為 cin int A=0,B=0,i; //奇數和為A;.偶數合為B for(i=0;i<strlen(x);i++) //Strlen → 讀取字串的長度 { if(i%2==0) //位數整除為偶數 { //簡單來說 x[i] 為字元,要轉int型態,要相減ACSLL碼,得數 B += x[i]-'0'; } else { A += x[i]-'0'; } } //"%d" 整數 // "\n" 換行 //abs取絕對值 printf("ans:%d\n",abs(A-B)); } ``` ## python 攝氏 轉 華氏 ```python= #自訂一個函式 名叫做 CtoF1,攝氏溫度作為參數 def CtoF1(degreeC): #degreeF 是自訂函數內新增的變數 degreeF = degreeC * 1.8 + 32 print('攝氏',degreeC,'度可以轉換成華氏',degreeF,'度') #顯示或回傳直 #eval 計算 temperatureC = eval(input('請輸入攝氏溫度:')) CtoF1(temperatureC) ``` ## Python 爬蟲 <font size=5> python 官網下載 python 下載 anaconda windows 設定 >> 進階系統設定 ![](https://i.imgur.com/QgmBQX8.png) 環境變數設定 >> "系統變數"欄位 新增 名稱'Path' ![](https://i.imgur.com/ZJMvZb8.png) 路徑取得方式: 在 python 裝好後 從C槽找到檔名為"pip3" 或者 pip 檔案路徑 > EX:C:\Users\user\anaconda3\Scripts ![](https://i.imgur.com/3yinp6V.png) 命令提示字元CMD 輸入 pip install BS4 ![](https://i.imgur.com/mgCMY22.png) open spider ![](https://i.imgur.com/4IVyCU9.png) coding ![](https://i.imgur.com/wEbO9tt.png]) ```python= # import requests from bs4 import BeautifulSoup R = requests.get("https://travel.ettoday.net/category/%E6%A1%83%E5%9C%92/") S = BeautifulSoup(R.text,"html.parser") print(S.prettify()) #輸出排版後的HTML內容 #抓取網頁資料, 以text方式存成property , 再以html.parser解析氣去將內容印出 ``` ```python= #changyu code import requests from bs4 import BeautifulSoup R = requests.get("https://tw.stock.yahoo.com/quote/2451") S = BeautifulSoup(R.text,"html.porser") A=S.find("h3") print(A) ``` ```python= #### 爬蟲基礎 #### # -*- coding: utf-8 -*- """ Spyder Editor This is a temporary script file. """ import requests from bs4 import BeautifulSoup response = requests.get("https://travel.ettoday.net/category/%E6%A1%83%E5%9C%92/") S = BeautifulSoup(response.text, "html.parser") '''find()''' #只尋找第一個符合條件的節點 A = S.find("h3") print(A) '''find_all()''' 使用關鍵字參數(Keyword Argument)指定其屬性值 利用list 增加複數個節點名稱 find_all(["節點名1","節點名2"], itemprop = "屬性值", limit= 節點個數限制) All = S.find_all("h3", itemprop="headline", limit=3) print(All) '''select搜尋多個子節點''' #搜尋多個子節點 #<div>底下有許多<a>子節點, 將所有子節點內容以list輸出 result = S.find("div", itemprop="itemListElement") print(result.select("a")) '''select_one()搜尋單個子節點''' result3 = S.find("h3", itemprop = "headline") print(result3.select_one("a")) '''get()取得屬性值''' titles = S.find_all("h3", itmeprop="headline") for title in titles: print(title.select_one("a").get("href")) '''getText()取得連結文字''' titles2 = S.find_all("h3", itemprop = "headline") for title in titles: print(title.select_one("a").getText()) ``` Out put ![](https://i.imgur.com/ufBs3ZZ.png) </font> ## [C++] 指標與陣列(Pointer & Array) 程式語言就是跟電腦描述如何處理資料,所以要充分瞭解每個程式語言對資料型態的定義,C/C++因為更貼近記憶體的運作來設計,所以很多觀念在描述上略為抽象,在學習上需要格外費心。 建議手繪來幫助記憶。 ### 複合資料型別 (compound type) 相較於基本型別int, double,C++還有一種複合資料型別。 其中很重要,會常用到的複合資料型別,就是參考(reference)、指標(pointer)、陣列(Array) #### 參考(Reference) 1. 參考的定義 ``` C++ #include <iostream> using namespace std; int main() { int i = 1, j = 2; int &r = i; //i is referenced by r cout << "address of r: " <<&r << endl; cout << "address of i: " <<&i << endl; return 0; } ``` ![](https://i.imgur.com/FO6Xszt.png) 2. 參考本身不是一個物件,而是對於一個**已存在物件**取別的名稱 ### 指標(Pointer) 1. 指標本身是一個物件,指向任何一個**已存在物件**,可以被指定或拷貝 - 指標宣告時,就要定義是指向哪種資料型態的物件 - 指標本身儲存的值,有三種情況 - 指向一個物件,值裡面存放另一個物件的位址 - 指向另一個物件尾端後的位置 - 沒有指向任何物件,值即為null ``` C++ int i = 42; int *p = &i; //p指向i ``` 2. 當一個指標指向一個物件,我們可以使用解參考(dereference)運算子*來存取物件 ``` C++ #include <iostream> using namespace std; int main() { int i = 42; int *p = &i; //p指向i cout << *p << endl; //印出指標p所指向物件i的值,即42 *p = 0; //因為p指向i,所以實際是i的值被改變成0 cout << i <<endl; //印出指標p所指向物件i的值,即0 return 0; } ``` 3. 關鍵觀念:*, &的符號多重意義 ``` C++ #include <iostream> using namespace std; int main() { int i = 42; int &r = i; //& 跟在一個型別,且是宣告的一部份,所以r是一個reference int *p; //* 跟在一個型別,且是宣告的一部份,所以p是一個pointer p = &i; //& 被用在運算式中,做為address-of 運算子 *p = i; //* 被用在運算式中,做為dereference運算子 int &j = *p; //& 是宣告的一部分;* 是dereference運算子 cout << "i: " << i << endl; cout << "&i: " << &i << endl; cout << "r: " << r << endl; cout << "&r: " << &r << endl; cout << "*p: " << *p << endl; cout << "p: " << p << endl; cout << "j: " << j << endl; cout << "&j: " << &j << endl; return 0; } ``` ![](https://i.imgur.com/xP2L7xk.png) 4. void*指標:型別void*是一個特殊的指標型別,可以存放任何物件的位址 ### 陣列(Array) 1. 陣列的定義:是一個複合資料型別,放置**單一型別**物件的容器,並且以位置來存取它們,有固定的尺寸 2. 宣告與初始化陣列 ``` C++ int a[10]; //宣告一個10個int物件的陣列 int *p[10]; //宣告一個10個int指標的陣列 ``` 3. 指標算術 對一個指標做加減,會移動指向陣列中的位置 ``` C++ #include <iostream> using namespace std; int main() { int a[] = {1,2,3,4,5}; int *ip = a; //等同於int *ip = &a[0] int *ip2 = ip + 4; //ip2指向a[4] cout << ip2 << endl; return 0; } ``` ## 指標 [c語言-超好懂的指標,初學者請進~](https://reurl.cc/85kX8R) ![](https://i.imgur.com/Y2CryA7.png) <font size=5>==* 取值 // & 取址==</font> ![](https://i.imgur.com/iZzwUAo.png) > <font size=4>關於Line9:cout << "address of r:" << ==*r== << endl; > ==*r==:對應到 i 的址,"*" 取值,所以取 i 的值 ( A君理解 >> 取這個址的值) > 關於Line11:cout << "address of r:" << ==*&r== << endl; > ==*&r==:取r地址裡的值,而 ++r 的值為 i 的址++,所以結果為 i 的址 </font> ==指標重點註記== int *p 指標變數(當作是一種特殊的變數) *p = ??? 從後面指定位置取"值"(反查找值) &c &取"址" ```c= [雙重指標判讀標準 由右往左] int a; // 一個整型數 int *a; // 一個指向整數的指標 int **a; // 一個指向指標的指標,它指向的指標是指向一個整型數 int a[10]; // 一個有10個整數型的陣列 int *a[10]; // 一個有10個指標的陣列,該指標是指向一個整數型的 int (*a)[10]; // 一個指向有10個整數型陣列的指標 int (*a)(int); // 一個指向函數的指標,該函數有一個整數型參數並返回一個整數 int (*a[10])(int); // 一個有10個指標的陣列,該指標指向一個函數,該函數有一個整數型參數並返回一個整數 ``` ```c= [指標練習題 1] 判斷下列程式碼輸出結果 是/否包含位址 *c=&a / *c = a (純取值) No1. int main() { int a=17; int *c; *c = a; printf("c=%d ",*c); //17 printf("a=%d ",a); //17 *c = *c +3; //20 printf("c=%d ",*c); //20 printf("a=%d ",a); //17 a = a +5; //22 printf("c=%d ",*c); //20 printf("a=%d ",a); //22 } ``` ```c= [指標練習題 2] No2. int main() { int a=17; int *c = &a; printf("c=%d ",*c); //17 printf("a=%d ",a); //17 *c = *c +3; //20 printf("c=%d ",*c); //20 printf("a=%d ",a); //20 a = a +5; //25 printf("c=%d ",*c); //25 printf("a=%d ",a); //25 } ``` ---- ## 矩陣陣列練習 -- 小群體 ![](https://i.imgur.com/J50Nkft.png) ```c= #include <stdio.h> #include <stdlib.h> #include <string.h> //設定變數 num=好友總數 count=0 記數總和 //設定變數陣列 Friend=好友編號 TF=判斷是否讀取過 //&num → 將輸入的值存入位址值 //當陣列位置=自己的數字→沒有其他朋友,則Count++ //變數Next的值存取Friend的陣列位置 //用 if & //再以Next的值存取Friend的好友編號 //Count++ int main(){ int num,i,count = 0; //num 人數 , i圈數, count 確認是否數過 printf("輸入人數"); scanf("%d",&num); int Friend[num], TF[num]; //將使用者輸入的數 //以陣列儲存 for(i = 0;i < num;i++){ printf("請輸入不重複的編號"); scanf("%d",&Friend[i]); TF[i]=0; } //判斷群體數量 for(i = 0;i < num;i++){ //將有數過的人打勾勾 TF[i]=1; //邊緣人自己一群Q_Q if(Friend[i]==i){ count++; } //其他情況 else{ //讀取你的編號對應的好友編號是誰 int next = Friend[i //如果他沒有被點名過 if(TF[next]==0){ //用while意思是 直到回圈封閉為止, 再把群體+1 while(TF[next]==0){ TF[next] = 1; //把這一個冤家計次 next = Friend[next]; //去抓她的下一個冤家是誰 } count++; } } } printf("有%d個小圈圈",count); } ``` ## 邏輯運算子 ※此圖可在新分頁中開啟放大 ![](https://i.imgur.com/XXwRedo.png) ```c= #include <iostream> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <vector> using namespace std; int main(){ int a,b,c; while (cin >>a >> b >> c){ bool found = false; if (a>0) a=1; if (b>0) b=1; if ((a&b) ==c) { cout << "AND" <<endl; found = true; } if ((a|b) == c) { cout << "XOR" <<endl; found = true; } if (!found) { //若AND OR XOR 都沒有 cout << "IMPOSSIBLE" <<endl; } } } ``` ## 二分搜尋法 Binary Search ### 題目 [Here](https://leetcode.com/problems/minimum-cost-to-cut-a-stick/) ```c= class Solution { public: //設定一自訂函數名稱是search 參數1使用者提供一整數陣列 參數二為目標數字 int search(vector<int>& nums, int target) { //初始化索引值 左邊藉由索引0開始 右邊界數字為"個數-1" (因為編號從0開始) int left = 0; int right = nums.size() - 1; //左邊界<=右邊界才可進行搜尋, 否則指針會混亂 while(left<=right){ //計算中間的索引編號 int middle = left +(right-left)/2; //如果中間編號的值大於目標數字 ]要移到中間數字的左邊(-1) EX: [02 63 ]67 69 72 if (nums[middle]>target){ right= middle - 1; } //如果中間編號的值小於目標數字 [要移到中間數字的右邊(+1) EX: 02 63 67[ 69 72] else if(nums[middle]<target){ left = middle +1; } //如果中間編號的值等於目標數字 就是該索引值 else{ return middle; } } //如果左右邊界交叉, 則代表找不到 回傳-1 return -1; } }; //解二(切木頭要號多少力) #include <bits/stdc++.h> using namespace std; int l, n, A[55], memo[55][55]; int opt[55][55]; int cut(int left, int right) { if (left+1 >= right) { opt[left][right] = right; return 0; } int &ans = memo[left][right]; if (ans != -1) return ans; ans = 2e9; cut(left,right-1); cut(left+1,right); for (int i = opt[left][right-1]; i <= opt[left+1][right]; ++i) { int value = cut(left, i) + cut(i, right) + (A[right]-A[left]); if ( value < ans ) { ans = value; opt[left][right] = i; } } return ans; } int main() { while (scanf("%d", &l), l) { A[0] = 0; scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", &A[i]); A[n+1] = l; memset(memo, -1, sizeof memo); memset(opt, -1, sizeof(opt)); printf("The minimum cutting is %d.\n", cut(0, n+1)); // start with left = 0 and right = n+1 } return 0; } ``` ## 字串轉成小寫 說明:請寫一程式,將字串 "Good Morning" 轉成小寫 ```c= #include <stdio.h> #include <ctype.h> #include <stdlib.h> int main(){ int i=0; char str[20]="Good Morning"; while(str[i]!='\0’){ printf("%c",tolower(str[i])); i++; } system("pause"); } ``` ## 二元樹 一個樹如果每個節點都有兩個子節點就叫做二元樹 - 完整(Complete)二元樹 - 靠左中間沒有空隙的樹就是完整二元樹 - 高度是$lg(n) + 1$,n是節點數量 - 節點個數$2^{k-1} \le n \le 2^K - 1$,k是樹的高度 - 完滿(full)二元樹 - 如果每一層的節點不是0就是$2^k$就是完滿二元樹 - 是完整二元樹的子集 ### 二元樹走訪 ![](https://i.imgur.com/kl92Nwc.png) 前序: 1,2,4,7,8,5,3,6,9,10 中序: 7,4,8,2,5,1,3,9,6,10 後序: 7,8,4,5,2,9,10,6,3,1 ## 使用指標(含有鏈結串列) 建立二元樹 - 需要兩個指標(一個指向左子樹、一個指向右子樹)。 - 若子樹為空,設定為NULL。(走訪時若遇到NULL則倒退回去) ```c= #include <bits/stdc++.h> using namespace std; struct node{ //node p1 'A' 指向 node left 'B' 和 node right 'C' char data; struct node *left; struct node *right; }; void visit(node *p){ if(p){ cout << p->data << ' '; //前序走訪, 使用單向鏈結陣列儲存樹 visit(p->left); visit(p->right); } } int main(){ node *root,*p1,*p2,*p3,*p4,*p5,*p7; p1 = new node; p2 = new node; p3 = new node; p4 = new node; p5 = new node; p7 = new node; p1->data = 'A'; root=p1; p2->data = 'B'; p3->data = 'C'; p4->data = 'D'; p5->data = 'E'; p7->data = 'F'; p1->left = p2; p2->left = p4; p2->right = p5; p1->right = p3; p3->right = p7; p3->left = NULL; p4->left = NULL; p4->right = NULL; p5->left = NULL; p5->right = NULL; p7->left = NULL; p7->right = NULL; visit(root); } ``` ### About 二元搜索 LeetCode: 704-Binary Search [解題紀錄](https://clay-atlas.com/blog/2022/03/26/leetcode-704-binary-search/) ### 求二元樹根 & 最深子節點總和 ![](https://i.imgur.com/dqJbkIG.png) ![](https://i.imgur.com/xHIJIkG.png) ### 完整解 ```c= #include <iostream> #include <cstdio> #include <queue> #include <cstring> #define MAX 100001 //定義100001的別稱 ex define 花媽 陳菊 using namespace std; int p[MAX], d[MAX], num[MAX]; /*p[]紀錄爸爸是誰 d[]紀錄深度(depth) num[] 記錄子節點個數*/ deque<int> t; //deque:雙向佇列 int main() { int n,k,c; long long int sum; //為了避免儲存長度不足1+2+3+......+100001 使用到的byte //使用者輸入 while (scanf(%d,&n)!=EOF){ sum = 0; memset(d, -1,sizeof(d)); memset(p, 0, sizeof(p)); memset(num, 0, sizeof(num)); //使用編號紀錄每個子樹 for(int i,i<=n;i++){ scanf("%d",&k); //如果後面沒有人 if(k==0){ t.push_back(i);//push_back:把一個元素添加到尾端 (將葉節點放在尾端) d[i] = 0; //最尾端的葉節點高度為0 } //如果後面有子節點, 紀錄子代的父節點 else{ num[i] = k; for(int j =0; j<k ; j++){ scanf("%d",&c); p[c] = i; } } } int node; //容量 empty:回傳是否為空 t.empty 回傳訊息:空的1, 非空0 while(!t.empty()){ node = t.front() //front:取得第一個的元素 t.pop_front(); //pop_front:移除第一個元素(頭端) d[p[node]] = max(d[p[node],d[node]+1); /*p[node]父節點, d[p[node]]父節點目前的深度, d[node]子節點的深度+1就是父節點的深 度, 誰比較大就取他的值*/ num[p[node]]--; //一開始記錄子節點個數, 已完成計算高度的子節點就刪除了 所以個數-1 if(num[p[node]] == 0) //沒走過的子節點個數為0()都走完了 t.push_back(p[node]); //push_back:把一個元素添加到尾端 } for(int i= 1; i<=n; i++){ sum+=d[i]; } cout<<node<<endl; //最後一個取出來的會是根 cout<<sum<<endl; } } ``` ### 解析 p[] 紀錄該節點的父代 t: 讀取紀錄深度(還有根) num 子節點的個數 ```c= for(int i =1;i<=n;i++){ scanf("%d",&k); //如果後面沒有人 if(k==0){ t.push_back(i);//push_back:把一個元素添加到尾端 (將葉節點放在尾端) d[i] = 0; //最尾端的葉節點高度為0 } //如果後面有子節點, 紀錄子代的父節點 else{ num[i] = k; for(int j =0; j<k ; j++){ scanf("%d",&c); p[c] = i; } } } ``` ![](https://i.imgur.com/XuJTFw4.png) ```c= //節點編號node int node; //容量 empty:回傳是否為空 t.empty 回傳訊息:空的1, 非空0 while(!t.empty()){ node = t.front() //front:取得第一個的元素 t.pop_front(); //pop_front:移除第一個元素(頭端) d[p[node]] = max(d[p[node]],d[node]+1); /*p[node]父節點, d[p[node]]父節點目前的深度, d[node]子節點的深度+1就是父節點的 深度, 誰比較大就取他的值*/ num[p[node]]--; //一開始記錄子節點個數, 已完成計算高度的子節點就刪除了 所以個數-1 if(num[p[node]] == 0) //沒走過的子節點個數為0()都走完了 t.push_back(p[node]); //push_back:把一個元素添加到尾端 } ``` t.empty 回傳訊息:空的1, 非空0 (False) !(t.empty) 回傳訊息:空的0, 非空1(True) memset(p, 0, sizeof(p)); p裡面的元素初始值皆為0 memset(d, -1,sizeof(d)); d裡面的元素初始值皆為-1 memset(num, 0, sizeof(num)); ![](https://i.imgur.com/kSTZrQ8.png) ![](https://i.imgur.com/AKM1G3p.png) - <font size=5>EOF: [C/C++中的結束輸入條件判斷](https://www.796t.com/content/1549363335.html)(scanf、EOF、getchar()、cin.get()、getline) </font> > 說明:輸入的測試樣例有多組,每組需要相同邏輯的處理 > 處理方案:在C語言中可利用scanf("%d",&n)!=EOF,在C++中可以使用while(cin>>n > 例如:計算兩數之和,輸入可能有多組樣例。 > ```c= > #include <iostream> > using namespace std; > > int main(){ > int a,b; > while(scanf("%d %d",&a,&b)!=EOF){ > cout<<a+b<<endl; > } > return 0; > } > ``` - <font size=5>memset(): [C/C++ memset 用法與範例](https://shengyu7697.github.io/cpp-memset/)</font> - 使用需引標頭檔cstring - 用法 memset ( 容器, 填入的初始值, 數量) > ```c= > void * memset(void * ptr, int value, size_t num); > ``` - <font size=5>std::deque:[C++ std::deque 用法與範例](https://shengyu7697.github.io/std-deque/)</font> ## 費波那奇數列 ```c= 遞迴: 自身函數內呼喚自身函數 時間複雜度通常為O(2n) #include <iostream> using namespace std; //自訂函數:費波那奇數列 自身等於前兩項之和 int fib (int n){ if (n==0) return 0; if (n==1) return 1; return fib(n-1)+fib(n-2); } int main(){ int a,c; cin>>a; c = fib(a); //在main主程式中執行副程式 cout<<c; return 0; } 迭代: for O(n) (1) #include <iostream> using namespace std; int fib(int n) { int pre = -1; int result = 1; int sum = 0; for (int i = 0; i <= n; i++) { sum = result + pre; pre = result; result = sum; } return result; } int main(){ int a; cin>>a; cout<<fib(a); return 0; } (2) 迭代: 減少變數 #include <iostream> using namespace std; int fib(int n) { int pre = -1; //前前一項的常數 int i = n; //使用者輸入引數(需要帶入方程式的參數) 為迴圈執行的次數 n = 1; //前一項 int sum = 0; while(i>0){ i--; sum = n+pre; pre = n; //數列往後推移 n = sum; //將加總延續下去 } return n; } int maim(){ int a; cin>>a; cout<<fib(a); return 0; } ```

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully