joelccting
    • 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
    # 分類題庫 ## Linked List ### ZeroJudge b586. 文章壓縮 26/03/16 做一個linked list來存新的單字。按題目要求,把已經認識的單字,提到list前頭。 我犯過的儍: 1. strtok不適用,雖然它可以parse單字,卻會把comma搞不見。 2. scanf不適用,因為它會斷在句子的空白。用fgets或getchar取代之。 3. 不需要和'A'、'Z'、'a'、'z'比較,只要用isalpha即可確認。 4. 結束行0,使用strncmp比較一個字即可。 ```clike= // ZEROJUDGE b586. 文章壓縮 #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> typedef struct node { char *word; struct node *next; } Node; void move(Node *h, Node *prev, Node *curr) { Node *p = curr; prev->next = p->next; Node *first = h->next; p->next = first; h->next = p; } int search(Node *h, char *s) { Node *prev = h, *curr = h->next; int sn = 0; while (NULL != curr) { ++sn; if (!strcmp(curr->word, s)) { break; } prev = curr; curr = curr->next; } if (NULL == curr) { return -1; } // printf("[%d] %d:%s\n", __LINE__, sn, s); move(h, prev, curr); return sn; } void insert(Node *h, char *s) { int len = strlen(s) + 1; Node *p = (Node *)malloc(sizeof(Node)); p->word = (char *)malloc(len); memset(p->word, 0, len); strcpy(p->word, s); Node *np = h->next; p->next = np; h->next = p; } // void print(Node *h) // { // Node *p = h->next; // while (p) // { // printf("%s ", p->word); // p = p->next; // } // } void destroy(Node *h) { Node *p = h->next; while (NULL != p) { h->next = p->next; free(p->word); free(p); p = h->next; } free(h); } int main() { char ibuf[1001], word[51]; // char obuf[1001] = {0}; Node *head = (Node *)malloc(sizeof(Node)); head->next = NULL; // while (scanf("%[^\n]", ibuf)) while (fgets(ibuf, 1001, stdin)) { if (!strncmp(ibuf, "0", 1)) { break; } #if 0 const char *delim = " -,'"; char *pch = strtok(ibuf, delim); while (pch) { // printf("%s\n", pch); int v = search(head, pch); // int v = 0; if (-1 == v) { // printf("%s ", pch); insert(head, pch); } pch = strtok(NULL, delim); } #endif int i = 0, j = 0; while (ibuf[i]) { if (isalpha(ibuf[i])) { word[j] = ibuf[i]; ++i; ++j; } else { if (0 != j) { word[j] = 0; // printf("[%d] %s\n", __LINE__, word); int v = search(head, word); if (-1 == v) { printf("%s", word); // strcat(obuf, word); insert(head, word); } else { // char num[80]; printf("%d", v); // sprintf(num, "%d", v); // strcat(obuf, num); } j = 0; } // char punc[80]; printf("%c", ibuf[i++]); // sprintf(punc, "%c", ibuf[i++]); // strcat(obuf, punc); } } } // print(head); // printf("%s", obuf); destroy(head); return 0; } ``` ### ZeroJudge b938. kevin 愛殺殺 26/03/14 本題中「會叫編號k的人、把他後面的人殺掉」,故使用陣列來實做linked list,會比使用指標搜尋速度快。 ```clike= #include <stdio.h> #include <stdlib.h> typedef struct node { int sn; int next; } Node; void init(Node *head, int n) { for (int i = 1; i <= n - 1; ++i) { head[i].sn = i; head[i].next = i + 1; } head[n].sn = n; head[n].next = -1; } void print(Node *head) { Node *p = head + 1; while (-1 != p->next) { printf("%d,", p->sn); p = head + p->next; } printf("%d\n", p->sn); } void del(Node *h, int k) { int k1 = h[k].next; if (-1 != k1) { h[k].next = h[k1].next; h[k1].next = -1; printf("%d\n", k1); } else { printf("0u0 ...... ?\n"); } } int main() { int n, m; scanf("%d %d", &n, &m); Node *head = (Node *)malloc(sizeof(Node) * (n + 1)); init(head, n); // print(head); while (m--) { int k; scanf("%d", &k); del(head, k); } free(head); return 0; } ``` ## 參考資料 1. 林盈達. 大學程式能力檢定: CPE祕笈. 二版. 臺北市: 美商麥格羅希爾國際股份有限公司臺灣分公司, 2021. Print. 1. 增井敏克., and 許郁文. 培養刷題基本功: Python程式設計師的頭腦體操. 初版. 臺北市: 碁峰資訊, 2021. Print. 1. 付東來. 刷題實戰筆記: 演算法工程師求職加分的祕笈. 初版. 新北市: 博碩文化, 2021. Print. 1. 林奈爾, Reuven M Lerner, and 施威銘研究室. Python刷題鍛鍊班: 老手都刷過的50道程式題,求職面試最給力. 初版. 臺北市: 旗標發行, 2021. Print.

    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