Grasping631
    • 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 No publishing access yet

      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.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      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
    • Make a copy
    • 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 Make a copy 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 No publishing access yet

    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.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    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
    --- type: slide ###### tags: `資研` --- # If else 條件判斷 ## 第2-0節社課 ---- ### 在開始之前... - 聯合迎新事宜宣布 (by社長) - 家長同意書 - Zerojudge課程加入 - 課程代碼: OizLo5 - Slido 匿名提問 - #4077250 - 回想上次的內容 ---- ### 經典joke ![](https://i.imgur.com/Yt4axub.png) ---- ### What is 條件判斷 - Example: 買一顆蘋果。**如果**++有雞蛋++,買六顆。 - 條件(condition): 有雞蛋? if 成立 (True) -> 買六顆 else 不成立 (False) -> 買一顆 ---- ### What is 條件判斷 - Scratch be like: ![](https://i.imgur.com/Gtmhmrm.png) ---- ### What is 條件判斷 - C++ be like: ```cpp= #include <iostream> using namespace std; int main(){ bool egg = true; if(egg == true){ cout << "Buy six apples" ; } else{ cout << "Buy one apple" ; } } ``` ---- ### What is 條件判斷 - C++ be like: ![](https://i.imgur.com/jfhUFh5.png) ---- ### 運算子複習-1 | 關係運算子 | 意思 | | -------- | -------- | | == | 等於 | | != | 不等於 | | < | 小於 | | <= | 小於等於 | | > | 大於 | | >= | 大於等於 | ---- ### 運算子複習-2 | 邏輯運算子 | 意思 | | -------- | -------- | | && | 且(AND) | | \|\| | 或(OR) | | ! | 否定(NOT) | ---- ### 運算子 - 比較兩數的關係 - 運算結果會是布林值(bool) -> true(1) / false(0) ---- ### 單向選擇結構 #### (if statement) ![](https://i.imgur.com/1Xa0O8C.png) ---- ### 單向選擇結構 ```cpp if( 條件式 ){ 條件成立(數值不為0)時,需執行的敘述; } ``` ---- ### 雙向選擇結構 #### (if...else statement) ![](https://i.imgur.com/akkxG5F.png) ---- ### 雙向選擇結構 ```cpp if( 條件式 ){ 條件成立時,需執行的敘述1; } else{ 條件不成立時,需執行的敘述2; } ``` ---- ### 多向選擇結構 #### (if...else if...else statement) ![](https://i.imgur.com/3sGr5nN.png) ---- ### 多向選擇結構 #### (if...else if...else statement) ```cpp if( 條件式A ){ 條件成立時,需執行的敘述1; } else if( 條件式B ){ 條件成立時,需執行的敘述2; } else{ 條件都不成立時,需執行的敘述3; } ``` ---- ### 運算優先順序 #### (Operator Precedence) 1. ! (否定) 2. 四則運算 由左至右、括號優先 (1) * / % (2) + - 3. 關係運算子 (1) 大小判斷 (2) 相等/不相等 4. 邏輯運算子 ---- ### 巢狀if #### (Nested if) - if 裡面包 if ```cpp int score; cin >> score; if (score < 60) { cout << "嗚嗚嗚要補考" << endl; if (score < 40) { cout << "嗚嗚嗚重補修" << endl; } } ``` ---- ### 使用 if 的注意事項 1. 使用多個 if 可能會造成預期外的結果 when 同時符合兩個 if 中的條件 2. 關係運算子之間用邏輯運算子連接 **不可以**連續使用 例子: 1<x<6 (X) | 1<x && x<6 (O) ---- ### Zerojudge 題目練習 1. [a003 兩光法師占卜術](https://zerojudge.tw/ShowProblem?problemid=a003) 2. [a006 一元二次方程式](https://zerojudge.tw/ShowProblem?problemid=a006) 3. [a053 Sagit's 計分程式](https://zerojudge.tw/ShowProblem?problemid=a053) 4. [a012 10055 - Hashmat the Brave Warrior](https://zerojudge.tw/ShowProblem?problemid=a012) 5. [e835 p2.表演座位 (Seats)](https://zerojudge.tw/ShowProblem?problemid=e835) ---- ### meme ![](https://i.imgur.com/GvOI1Em.png) ---- ![](https://i.imgur.com/7bTzHxh.png) --- # for、while迴圈 ## 第2-1節社課 ---- ### What is 迴圈(loop) - 假設你今天想叫電腦輸出1~100 - ctrl+c ctrl+v 好幾行的cout? ---- ### 現代問題需要現代手段 - 迴圈是重複作業的好幫手 ~~,因為它不會累~~ ---- ### while 迴圈 #### (while loop) ![](https://i.imgur.com/iThiNhS.png) ---- ### while 迴圈 #### (while loop) ```cpp while( 條件式 ){ 條件成立時,需執行的敘述; } ``` ---- ### while 迴圈 #### (while loop) - 輸出 1~100 ```cpp! int x=1; while( x<101 ){ cout << x << endl; x++; } ``` ---- ### 迴圈控制 1. break 跳出整個迴圈 2. continue 跳出這一次的迴圈,跑下一圈 ---- ### EOF(End of file) - 出現於 [a004 文文的求婚](https://zerojudge.tw/ShowProblem?problemid=a004) - 輸入說明:輸入有若干行直到 EOF 結束,每行包含一個整數代表年份 - 當有輸入進來,程式就不要停下 ```cpp! int year; while(cin>>year){ ... } ``` - 自己測試時可在小黑窗按ctrl+D模擬測資的EOF ---- ### for 迴圈 #### (for loop) ![](https://i.imgur.com/cvfIl3Z.png) ---- ### for 迴圈 #### (for loop) ```cpp for( 初始 ; 條件 ; 更新){ 條件成立時,需執行的敘述; } ``` ---- ### 初始值宣告 ![](https://i.imgur.com/uL1XgRF.png) ---- ### 初始值宣告 - 可以為空 -> 不做事 - 可以一次宣告多個變數 ---- ### 更新 - 每跑完一圈,變數要如何變化 - 可以為空 -> 不做事 - 可以一次改變多個數 - 加減乘除 ex. i++、i-\- ... ---- ### for 迴圈 #### (for loop) - 輸出1~100 ```cpp for(int i = 1 ; i <= 100 ; i++){ cout << i << endl; } ``` ---- ### 巢狀迴圈 #### (Nested loop) - 迴圈裡面包迴圈 ```cpp for(int i = 5 ; i <= 10 ; i++){ for (int j = 1 ; j <= i ; j++){ for (int k = 1 ; k <= j ; k++){ ... } } } ``` ---- ### 使用迴圈的注意事項 1. 無限迴圈 -> TLE 通常是迴圈結束條件寫錯造成的 2. for()裡面宣告的東西只能在for裡面用 3. while 跟 for 要用哪個 - while -> 不知道要跑幾次但知道條件 - for -> 知道要跑幾次 ---- ### 補充 - if 跟 for 裡面如果只有一行 可以省略大括號 ```cpp if(a > b) cout<< a <<endl; ... ``` ```cpp for(int i = 1 ; i < 11 ; i++) cout << i << endl; ... ``` ---- ### Zerojudge 題目練習 1. [a004 文文的求婚](https://zerojudge.tw/ShowProblem?problemid=a004) 2. [a005 Eva的回家作業](https://zerojudge.tw/ShowProblem?problemid=a005) 3. [d074 電腦教室](https://zerojudge.tw/ShowProblem?problemid=d074) 4. [c013 00488 - Triangle Wave](https://zerojudge.tw/ShowProblem?problemid=c013) 5. [c005 10300 - Ecological Premium](https://zerojudge.tw/ShowProblem?problemid=c005) ---- ### 其他練習 1. 輸出一個99乘法表 2. 輸出各種用符號做成的圖案 ---- ###### tags: `資研`

    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
    Sign in via Google Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    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