NCRL_09
      • 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
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners 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
    • 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 Help
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
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners 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
    計算機程式 2020 fall === ###### tags: `計算機程式` [TOC] ## WEEK 1 ### 1-2 DEC->BIN ``` cpp=1 #include <iostream> #include <cstdlib> using namespace std; int main() { int num = 0; //param for DEC int bin_counter = 0; //param to count int bin[100]={0}; //array to save BIN value cin >> num; //input number if (num == 0) //deal with number if it's zero bin_counter = 1; else { for(bin_counter = 0 ; num > 0 ; bin_counter++ ) //break if num greater than zero , it means it can't be devided by 2 anymore { bin[bin_counter] = num % 2; //get r num /= 2; // num = num/2; } } for (int j = bin_counter - 1; j >= 0; j--) //print bin value inversely cout << bin[j] << " "; system("paunse"); return 0; } ``` >[name=逸男] ## WEEK 2 ### 2-1 Calendar ```cpp=1 #include <cstdlib> #include <iostream> using namespace std; int main(void){ int month, date, output=0; int days[] = {31, 29 ,31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; cout << "Please input month and date" << endl << "month: "; cin >> month; cout << "date: "; cin >> date; if( month >= 1 && month <= 12 && date > 0 && date <= days[month-1] ){ for(int i=0; i < month-1; i++){ output += days[i]; } output += date; cout << "output: " << output; }else{ cout << "Your input is wrong. haha"; } return 0; } ``` >[name=D暉] ### 2-2 Sum ```cpp=1 # include <iostream> # include <cstdlib> using namespace std; void Sum(long long int &a, long long int &b); // declare the function with reference arguments int main(void){ int a, b; cin >> a >> b; Sum(a, b); // call the function cout << a << endl; system("pause"); return 0; } void Sum(long long int &a, long long int &b){ a = a + b; // save the result to a } ``` >[name=吉他之神] ### 2-3 Sort ```cpp=1 # include <iostream> using namespace std; void Sort(int &a, int &b){ if ( b > a ){ int tmp = a ; a = b; b = a; } } int main(void){ int a, b; cin >> a >> b; Sort(a, b); // call the function cout << a << " " << b << endl; } ``` >[name=大神] ## WEEK 3 ### 3-1 randomly choose 4 different numbers ```cpp=1 # include <iostream> # include <cstdlib> # include <ctime> using namespace std; # define NUMBER_OF_DIFFFERENT_DIGITS 4 // can be customized. int main(void){ srand(time(NULL)); // set the random seed. int check[10] = {0}; // check whether the digit is exist. 1 means exist, 0 means not. int number; for (int i = 0; i < NUMBER_OF_DIFFFERENT_DIGITS; i++){ if (i == 0){ // first digit can not be zero. number = rand() % 9 + 1; // number within 1~9. } else{ number = rand() % 10; // number within 0~9. while (check[number] != 0){ // while number is exist then randomly generate again. number = rand() % 10; } } check[number] = 1; // mark the number to prevent using again. cout << number; } cout << "\n"; return 0; } ``` >[name=吉他之神] ## WEEK 4 ### 4-3 encoding ``` C++=1 #include <iostream> #include <cstdlib> #include <ctime> using namespace std; int main(){ string str; int num; cin >> str; cin >> num; for (int i=0 ;i<str.length();i++) cout <<(char)(str[i] + num); } ``` ``` cpp=1 # include <iostream> # include <cmath> using namespace std; void print_log(int num){ cout << log10(num) << endl; // call log10 function in <cmath> library } int main(void){ int num; cin >> num; print_log(num); // call self-defined function return 0; } ``` >[name=神宗翰] ### 4-2 power ```cpp=1 #include <iostream> float pow(const double a,int b){ float data=1; for(int i = 0;i<b;i++){ data*=a; } return data; } int pow(const int a,int b){ int data=1; for(int i = 0;i<b;i++){ data*=a; } return data; } using namespace std; int main(){ int a, c; float b; cout << "輸入正整數:"; cin >> a ; cout << "輸入浮點數:"; cin >> b; cout << "輸入指數:"; cin >> c; cout<<pow(a,c)<<endl; cout<<pow(b,c); } ``` >[name=大哥翰] ### 4-3 Array and Random ```cpp=1 #include <cstdlib> #include <iostream> #include <ctime> using namespace std; void find_max(int arr[3], int* Max){ for (int i = 0; i < 3; i++){ if (*Max < *(arr+i)){ *Max = *(arr+i); } } } int main(void){ int arr[3], Max=0; srand(time(NULL)); for(auto offset = begin(arr); offset !=end(arr); offset++){ *offset = rand()%10 + 1; cout << *offset << " "; } cout <<endl; find_max(arr, &Max); cout << Max << endl; return 0; } ``` >[name=QQ龍的小夫] ## week 5 ``` C++ #include <iostream> #include <cstdlib> #include <ctime> using namespace std; int main(){ string str[3] ; int bill_line , flag; for(int i = 0 ;i<3;i++) { getline(cin,str[i]); } for(bill_line = 0 ;bill_line<3;bill_line++) { flag = str[bill_line].find("BILL"); if (flag != -1 ){ break; } } cout << bill_line+1 << endl; cout << flag <<endl; } ``` >[name=NCRL狗] ## Midterm ### week1_rectangle ```cpp=1 # include <iostream> using namespace std; int main(void){ int length = 0, width = 0; cout << "length: " << endl; cin >> length; cout << "width: " << endl; cin >> width; for (int i=0; i < length; i++) { if (i == 0 || i == (length-1)) { for (int j=0; j < width; j++) cout << "*"; cout << endl; } else { for (int j=0; j < width; j++) { if (j == 0 || j == (width-1)) { cout << "*"; } else { cout << " "; } } cout << endl; } } return 0; } ``` ### week1_scorePassFailed ```cpp=1 # include <iostream> using namespace std; typedef struct classes{ int pass; int failed; classes() { pass = 0; failed = 0; } }classes; int main(void){ int num = 5; int score[num]; classes myClass; while (num--) { cin >> score[num]; if (score[num] >= 60) { myClass.pass++; }else myClass.failed++; } cout << "pass: " << myClass.pass << endl; cout << "failed: " << myClass.failed; } ``` ### week1_Armstrong ```cpp=1 # include <iostream> # include <cmath> using namespace std; int count_digit(int num){ if (num == 0) return 1; int digit = 0; while(num){ digit++; num /= 10; } return digit; } int Armstrong(int num, int digit){ int arr[digit], ans = 0; for (int i = 0; i < digit; i++){ arr[i] = num % 10; num /= 10; } for (int i = 0; i < digit; i++){ ans += pow(arr[i], digit); } return ans; } int main(void){ int low, high, exist = 0; cin >> low >> high; for (int i = low; i < high; i++){ int digit = count_digit(i); if (Armstrong(i, digit) == i) { cout << i << " "; exist = 1; } } if (exist == 0) cout << "none"; cout << endl; return 0; } ``` ### Week1 Simple substitution cipher ```cpp=1 #include <iostream> #include <cstdlib> #include <cmath> #include <cstring> using namespace std; int main(){ char map_array[27]; char key[26]; char plain[50]; int flag = 0; int n = 0; cin>>key; strcpy (map_array,key); for(int i = strlen(map_array) ; i < 26 ; i++){ do{ flag = 0; for(int j = 0 ; j<i ; j++ ){ if(('a'+ n) == map_array[j]){ n++; flag = 1; break; } } }while(flag == 1); map_array[i] = 'a'+n; } map_array[26] = '\0'; cout <<map_array<<" "<<strlen(map_array)<<endl; cin >> plain; for(int i = 0 ;i<strlen(plain);i++){ plain[i] = map_array[plain[i]-'a']; } cout << plain; } ``` <!-- ### week2_triangle ```cpp=1 # include <iostream> using namespace std; int main(void){ int width = 0; cout << "width: " << endl; cin >> width; for (int i=0; i <= (width-1)/2; i++) { for (int j=0; j < (width-1)/2 - i; j++) { cout << " "; } for (int j=0; j < 1 + 2*i; j++) { cout << "*"; } cout << endl; } return 0; } ``` ### week2_student score ```cpp=1 #include <iostream> #include <cmath> using namespace std; typedef struct student{ string id; double score = 0; }student; int main(void){ int num = 5; student students[num]; for (int i=0; i < num; i++) { cin >> students[i].id >> students[i].score; students[num].score = pow(students[num].score, 0.5)*10; } for (int i=0; i < num; i++) { cout << "id: " <<students[i].id << "\t score: " << students[i].score << endl; } return 0; } ``` ### Week2 bouble sort with student score ```c++=1 #include <iostream> using namespace std; typedef struct student{ int student_id = 0; int score = 0; }student; void swap(student &a,student &b){ student tmp ; tmp = a; a = b; b = tmp; } int main() { int student_num = 0; cin>>student_num; student class_student[20]; for(int i = 0 ; i<student_num ; i++){ cin >> class_student[i].student_id; cin >> class_student[i].score; } for(int i=student_num ; i>=0 ; i--){ for(int j = 0 ; j<i-1 ; j++){ if(class_student[j].score>class_student[j+1].score) swap(class_student[j+1],class_student[j]); } } for (int i = 0 ; i<student_num; i ++){ cout << class_student[i].student_id<<" "; } return 0; } ``` --> ## final ```cpp=1 # include <iostream> using namespace std; void fun(int b){ int a = 8; a++; b--; } int main(void){ int a = 0; a += 1; a *= 2; --a; fun(a); cout << a << endl; // a = ? return 0; } ``` ```cpp=1 # include <iostream> using namespace std; int sum(int num1, int num2){ return num1 + num2; } float sum(float num1, float num2){ return num1 + num2; } int main(void){ int a = 1, b = 2, ans1; float c = 1.1, d = 2.2, ans2; ans1 = sum(a, b); ans2 = sum(c, d); cout << ans1 << endl; // ans1 = ? cout << ans2 << endl; // ans2 = ? return 0; } ``` ```cpp=1 # include <iostream> using namespace std; int sum(float num1, float num2){ return num1 + num2; } float sum(float num1, float num2){ return num1 + num2; } int main(void){ int a = 1, b = 2, ans1; float c = 1.1, d = 2.2, ans2; ans1 = sum(a, b); ans2 = sum(c, d); cout << ans1 << endl; // ans1 = ? cout << ans2 << endl; // ans2 = ? return 0; } ``` ![](https://i.imgur.com/VJoP6xj.png) ```cpp=1 # include <iostream> # include <cstdlib> using namespace std; int main(void) { int a = 5, b = 10; int *ptr1, *ptr2; ptr1 = &a; ptr2 = &b; *ptr1 = 7; *ptr2 = 32; a = 17; ptr1 = ptr2; *ptr1 = 9; ptr1 = &a; a = 64; *ptr2 = *ptr1 + 5; ptr2 = &a; system("pause"); return 0; } ``` ## week 12 ```cpp = 1 #include <iostream> #include <math.h> using namespace std; class shape { public: shape(string Obj, int Num_edges): obj(Obj), num_edges(Num_edges) { cout << "create a " << obj << endl; edges = new double[num_edges]; } void set_edges(double* Edges) { edges = Edges; } double* get_edges() const { return edges; } int get_num_edges() const { return num_edges; } virtual double area() const = 0; ~shape() { delete [] edges; } private: string obj; int num_edges; double* edges; }; class triangle: public shape { public: triangle(double* Edges): shape("triangle", 3) { set_edges(Edges); } double area() const { double* ptr = get_edges(); int num_edges = get_num_edges(); return ptr[0]*ptr[1]/2; } }; class circle: public shape { public: circle(double Edge): shape("circle", 1) { set_edges(&Edge); set_radius(Edge); } void set_radius(double edge) { radius = edge / (2 * M_PI); } double area() const { return radius*radius*M_PI; } private: double radius; }; int main() { double tt_edges[] = {30.0, 40.0, 50.0}; triangle tt(tt_edges); cout << tt.area() << endl; double cc_edge = 2*M_PI; circle cc(cc_edge); cout << cc.area() << endl; 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