許嘉麟
    • 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
    • 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

    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
    {%hackmd hackmd-dark-theme %} <style> h2 { color: rgb(153, 50, 204) !important; } </style> :::spoiler **Python** ## HW3 請實作一程式,此程式可以要求使用者輸入10組資料。每次所輸入一組資料的內容如下所示: O d1 d2 O代表指令動作 當O為1時,則請由小到大輸出d1以及d2所有小於100的共同因數 當O為2時,則請由小到大輸出d1以及d2所有小於100的共同倍數,若無,則印出None | <div style="width:290px">輸入資料</div> | <div style="width:290px">輸出結果</div> | | -------- | -------- | | 1 10 20 | 1 2 5 10 | | 2 50 60 | None | | 2 30 45 | 90 | ```python= for i in range(0,10): o,d1,d2 = input().split() o=int(o)#改變型態 d1=int(d1)#改變型態 d2=int(d2)#改變型態 if(o==1): i=0 while(i<100):#因數 i=i+1 if(d1 % i==0 and d2 % i==0): print(i) else: i=0 j=0 while(i<100): i=i+1 if(i%d1==0 and i%d2==0): j+=1 print(i) if(j==0): print("None") ``` ###### tags: `Program` ## HW4 請實作一程式,此程式可以要求使用者輸入三行字串,當輸入完一行字串後,請計算在此字串中字元a~zA~Z所出現的頻率次數,請輸出頻率次數非零的字元(請依a~zA~Z順序輸出)以及其頻率次數。 請用連續星星符號個數來代表頻率次數,如出現N次,請以N個星星符號表示。 | <div style="width:290px">輸入資料</div> | <div style="width:290px">輸出結果</div> | | -------- | -------- | | Hello World |d * e * l *** o ** r * H * W * | | Good Morning, everyone. |d * e *** g * i * n *** o **** r ** v * y * G * M * | | byebye |b ** e ** y ** | ```python=1 for _ in range(3): array1 = [0] * 26 array2 = [0] * 26 for x in input(): if x.islower():#檢查是否為小寫字母 array1[ord(x) - 97] += 1 elif x.isupper():#檢查是否為大寫字母 array2[ord(x) - 65] += 1 for i, cnt in enumerate(array1): if cnt > 0: print(chr(i + 97), '*' * cnt, end=' ') for i, cnt in enumerate(array2): if cnt > 0: print(chr(i + 65), '*' * cnt, end=' ') ``` ## HW5 請實作一程式,此程式可以要求使用者輸入一整數N,若N>0,則接下來會請使用者輸入N組資料,每一組資料格式如下所示: L TOKEN1 TOKEN2 L代表要輸出L * L個圖案,左下方的圖案為TOKEN1,其餘圖案為TOKEN2 TOKEN1或TOKEN2不能為空白、\t 或 \n 舉例,假設TOKEN1 = ‘$’,TOKEN2 = ‘@’,則 請用連續星星符號個數來代表頻率次數,如出現N次,請以N個星星符號表示 | <div style="width:290px">輸入資料</div> | <div style="width:290px">輸出結果</div> | | -------- | -------- | | 3 || | 5 @ # |@####<br /> @@###<br /> @@@##<br /> @@@@#<br /> @@@@@ | | 7 & * |&******<br /> &&*****<br /> &&&****<br /> &&&&***<br /> &&&&&**<br /> &&&&&&*<br /> &&&&&&&| ```python= for _ in range(int(input())): l,a,b=input().split() l = int(l) for i in range(1, l+1): print(a*i+b*(l-i))#字串可相加相乘 ``` ## HW6 剪刀石頭布遊戲是我們日常生活中常玩的一個小遊戲,常以三戰兩勝或五戰三勝或N戰(N+1)/2勝等結果來決定最後的勝負。當我們用Y代表剪刀、M代表石頭、O代表布,請試做一程式可以允許使用者可以不斷地輸入一組資料,直到此組資料為不合法資料則結束程式。每組資料一開頭為N值(正奇數值,若不為正奇數值則為不合法資料),代表之後的勝負是幾戰幾勝,接下來輸入兩個人的出拳結果,請根據所輸入的資料並印出是第一個人或是第二個人贏得最終勝利。 假設第一個人贏,則顯示The first person wins the game 假設第二個人贏,則顯示The second person wins the game | <div style="width:290px">輸入資料</div> | <div style="width:290px">輸出結果</div> | | -------- | -------- | | 3 Y M O O Y Y O Y 5 | The second person wins the game| M Y M M O M Y O 0 |The first person wins the game| ```python= while True: n= int(input()) if n%2==0: break win = (n+1) // 2 a, b = 0, 0 while a < win and b < win: n1,n2=input().split() if n1=='Y'and n2=='O'or n1=='M' and n2=='Y' or n1=='O' and n2=='M': a+=1 elif n1==n2: continue else: b+=1 if(a>b): print("The first person wins the game") else: print("The second person wins the game") ``` ## HW7 請試做一程式,此程式可以允許使用者不斷地輸入一組資料,直到此組資料為不合法資料則結束程式。每組資料格式如下所示: k d1 d2 d3 k d1 d2 d3 均需為正整數 請根據每組資料,印出 d1, d2, d3 的前k小公倍數 | <div style="width:290px">輸入資料</div> | <div style="width:290px">輸出結果</div> | | -------- | -------- | |5 1 3 4 5 6 7|3 *** 4 26 28 |549828 19656 29484 39312 2 2 9 10|10 ********** 0|跳出 ```python= while True: k,n1,n2,n3=map(int,input().split()) if(k==0): break for i in range(n1*n2*n3+1): if i%n1==0 and i%n2==0 and i%n3==0: for j in range(1, k+1): print(i*j,end=' ') break ``` ::: :::spoiler **C** ## HW8 請實作一程式,此程式可以不斷地要求使用者輸入一組資料,直到此組資料的第一個數字不為正整數則結束程式。請根據每組資料的內容印出其相對應的結果。每組資料的格式內容如下所示: N O d1 d2 … dN N代表接下來有一個指令動作O以及N筆資料d1, d2, …, dN O為1時則請印出d1, d2, …, dN中最小的值,即minimum{d1, d2, …, dN},並印出相對應的星星(星星與星星之間沒有空白) O為2時則請印出d1, d2, …, dN中最大的值,即maximum{d1, d2, …, dN},並印出相對應的星星(星星與星星之間沒有空白) | <div style="width:290px">輸入資料</div> | <div style="width:290px">輸出結果</div> | | -------- | -------- | 5 1 3 4 5 6 7|3 ***| 2 2 9 10|10 ********** 0|跳出 ```c= #include <iostream> #include <algorithm> using namespace std; int main() { int n, o, ans, d; while (cin >> n && n != 0) { cin >> o >> ans; if (o == 1) { for (int i = 0; i < n - 1; i++) { cin >> d; if (ans > d) ans = d; } } else { for (int i = 0; i < n - 1; i++) { cin >> d; if (ans < d) ans = d; } } cout << ans << ' ' << string(ans, '*') << endl; } return 0; } ``` ## HW7 請實作一程式,此程式可以要求使用者輸入3組資料,每一組資料的格式如下所示: N1 N2 N3 請輸出每一組資料內三個數字的最小公倍數 | <div style="width:290px">輸入資料</div> | <div style="width:290px">輸出結果</div> | | -------- | -------- | 6 2 4|12 1 5 3|15 8 2 16|16 ```c= #include <iostream> #include <algorithm> using namespace std; int main() { for (int x = 1; x <= 3; x++) { int a[3]; cin >> a[0] >> a[1] >> a[2]; for (int i = 1; i <= a[0]* a[1] * a[2]; i++) { if (i % a[0] == 0 && i % a[1] == 0 && i % a[2] == 0) { printf("%d\n", i); break; } } } return 0; } ``` ## HW6 請實作一程式,此程式可以要求使用者輸入3組資料,每一組資料的格式如下所示: N1 N2 N3 請輸出每一組資料內三個數字的最大公因數 | <div style="width:290px">輸入資料</div> | <div style="width:290px">輸出結果</div> | | -------- | -------- | 6 2 4|2 1 5 3|1 8 2 16|2 ```c= #include <iostream> #include <algorithm> using namespace std; int main() { for(int x=1;x<=3;x++) { int a[3]; cin >> a[0] >> a[1] >> a[2]; int maxma = max(max(a[0], a[1]), a[2]); for (int i = maxma; i >= 1; i--) { if (a[0] % i == 0 && a[1] % i == 0 && a[2] % i == 0) { printf("%d\n", i); break; } } } return 0; } ``` ## HW5 請實作一程式,此程式可以要求使用者輸入N組資料,每一組資料的格式如下所示: O N1 N2 O 為指令動作,只能是1 or 2 當O是1時,假設N1和N2的中最小值為MIN、最大值為MAX,請輸出從MIN到MAX範圍內的整數和,包含MIN及MAX。 當O是2時,請輸出從MIN到MAX範圍內的整數乘積,包含MIN及MAX。 | <div style="width:290px">輸入資料</div> | <div style="width:290px">輸出結果</div> | | -------- | -------- | 3| 1 1 10|55 2 1 10|3628800 1 10 1|55 ```c= #include <iostream> #include <algorithm> using namespace std; int main() { int k, a, b, c; cin >> k; for (int i = 0; i < k; i++) { int sum = 0; cin >> a >> b >> c; if (a == 1) { if (b > c)//b=1 c=10 { while (c <= b)//成立繼續 { sum += c; c++; } } else { while (b <= c) { sum += b; b++; } } printf("%d\n", sum); } else { sum = 1; if (b > c) { while (c <= b) { sum *= c; c++; } } else { while (b <= c) { sum *= b; b++; } } printf("%d\n", sum); } } return 0; } ``` ## HW4 請實作一程式,此程式可以要求使用者輸入3組資料,每一組資料包含9個數字,且每個數字範圍為[1,10] (包含1及10)。請輸出每一組資料的總和及中間值。 在此注意到的是,中間值為將輸入資料由小到大排列取第 (9+1)/2 個數字(即第五個數字) 舉例:假設輸入資料分別為 1 9 3 2 5 4 8 6 7 時 將此輸入資料排序的結果為 1 2 3 4 5 6 7 8 9,因此取排列好的第5個數字,即5 | <div style="width:290px">輸入資料</div> | <div style="width:290px">輸出結果</div> | | -------- | -------- | 1 9 3 2 5 4 8 6 7|45 5 1 1 3 2 5 4 8 6 7|37 4 7 6 8 4 5 2 3 1 1|37 4 ```c= #include <iostream> #include <algorithm> using namespace std; int main() { int n = 3; while (n--) { int nums[10] = {}; int total = 0; for (int i = 0; i < 9; i++) { cin >> nums[i]; total += nums[i]; } sort(nums, nums + 9); cout << total << " " << nums[4] << endl; } return 0; } ``` ## sort用法 ```c= #include <iostream> #include <algorithm> int main() { int arr[] = {4, 5, 8, 3, 7, 1, 2, 6, 10, 9}; std::sort(arr, arr+10); std::cout << "sort array by default (increasing):" << std::endl; for (int i = 0; i < 10; i++) { std::cout << arr[i] << " "; } std::cout << std::endl; return 0; } ``` 1 2 3 4 5 6 7 8 9 10 ## HW9 請實作一程式,此程式可以不斷地要求使用者輸入一值K,直到K<=0時結束程式。當一大於零的K值輸入後,請輸出相對應的K K乘法表。 當K為9時,即是九九乘法表 | <div style="width:290px">輸入資料</div> | <div style="width:290px">輸出結果</div> | | -------- | -------- | 1|1*1=1 2|1*1=1 1*2=2 2*1=2 2*2=4 3|1*1=1 1*2=2 1*3=3 2*1=2 2*2=4 2*3=6 3*1=3 3*2=6 3*3=9| |0|跳出 ```c= #include <iostream> #include <algorithm> using namespace std; int main() { int k; while(true) { cin >> k; if (k <= 0) break; for (int i = 1; i <= k; i++) { for (int j = 1; j <= k; j++) printf("%d*%d=%d ", i, j, i * j); printf("\n"); } } 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