--- tags: Computer Programming II image: https://i.imgur.com/Ngut6cI.png --- :::info 大家可以來幫忙整理 QA!(要登入才能編輯哦) 如果該問題已寄信但尚未回覆,請打上「助教xxx: :mailbox_with_mail:」 ::: # 程設二 作業 5 QA 整理 [TOC] 作業連結:[hw05](https://drive.google.com/file/d/1ro5HMjkgxd6ZbZHLQ3qvgywmcpnuxlZ7/view) <img src="https://i.imgur.com/Nx1pmxs.png" style="width: 300px; border-radius: 8px; animation: animation 5s ease-in-out infinite" /> | command | allowable | |:--------- |:----------:| | `curl` | :accept: | | `grep` | :accept: | | `cat` | :accept: | | `awk` | :accept: | | `apt` | :no_entry: | | `apt-get` | :no_entry: | | `ffmpeg` | :no_entry: | | `echo` | :question: | | `sed` | :question: | | 開放許願 | :question: | ## 1 Memory Monitor Q: 題目一的這句話 --kilo show output in kilobytes (<font color="#00f">default</font>) <font color="#00f">default</font> 有變色,那我們印出來要變色嗎? A: 不用 Q: 如果助教同時輸入 --bytes --mega --kilo 是三種都印還是報錯? A: 報錯(助教更正:不報錯,以最後出現的選項為主) Q: 如果助教同時輸入 -b --kilo 是印兩次還是報錯?( 還是印一次就好 ) A: 報錯(助教更正:不報錯,以最後出現的選項為主) Q.那--help可以跟其他選項配合嗎?? A.--help 存在就只會輸出 Usage Q:-s -c可以並存嗎? A:可以喔,就是 a 秒輸出 1 次,輸出 b 次就結束 Q.-s存在 -c不存在時,預設是無窮迴圈嗎? A.是 Q.如果-c存在 -s不存在時,間隔秒數預設多少?? A.就直接輸出 N 次就好 Q.秒數的參數可以放小數嗎?? A.不考慮小數 Q.-s 的參數是0,合法嗎? A:非法好了,我比較好改 Q: Mac 沒有 /proc/meminfo 怎麼辦? A: 裝虛擬機(或者可以先用下面的資料跑) <!-- Docker` --> <!-- wow --> `$ cat /proc/meminfo` MemTotal: 16274168 kB MemFree: 1984480 kB MemAvailable: 3848596 kB Buffers: 190284 kB Cached: 3040276 kB SwapCached: 19320 kB Active: 11254608 kB Inactive: 2086228 kB Active(anon): 9940320 kB Inactive(anon): 1441444 kB Active(file): 1314288 kB Inactive(file): 644784 kB Unevictable: 151968 kB Mlocked: 128 kB SwapTotal: 15624188 kB SwapFree: 14909948 kB Dirty: 336 kB Writeback: 0 kB AnonPages: 10255924 kB Mapped: 959308 kB Shmem: 1273536 kB KReclaimable: 246056 kB Slab: 544352 kB SReclaimable: 246056 kB SUnreclaim: 298296 kB KernelStack: 33616 kB PageTables: 134692 kB NFS_Unstable: 0 kB Bounce: 0 kB WritebackTmp: 0 kB CommitLimit: 23761272 kB Committed_AS: 43731324 kB VmallocTotal: 34359738367 kB VmallocUsed: 53580 kB VmallocChunk: 0 kB Percpu: 8480 kB HardwareCorrupted: 0 kB AnonHugePages: 0 kB ShmemHugePages: 0 kB ShmemPmdMapped: 0 kB FileHugePages: 0 kB FilePmdMapped: 0 kB CmaTotal: 0 kB CmaFree: 0 kB HugePages_Total: 0 HugePages_Free: 0 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kB Hugetlb: 0 kB DirectMap4k: 911712 kB DirectMap2M: 15747072 kB DirectMap1G: 0 kB 或用 Docker: ```sh docker run -it --rm -v $PWD:/usr/workspace -w /usr/workspace ubuntu:20.04 bash # Run bash in a container with ubuntu:20.04 image # -it: interactive tty # --rm: remove container after exit # -v: mount volume, current directory <-> /usr/workspace # -w: working directory of bash # note: tested on Apple Silicon macOS # use "exit" to exit the shell ``` BTW, 這是免洗 Ubuntu, 只有 mounted volume 內的會保留, 其他的重開後就會還原了 <!-- 可以試試看亂刪系統東西 --> Q: 題目一有這句話 `When printing the memory information, do not forget the unit and round off to the 2nd decimal place. ` 所以當 KB 換成 MB 如果是小數也要到小數後兩位嗎?還是可以取到整數位就好?(題目原意應該是%要取到小數後兩位,想再確認一下 MB 要不要) A: MB 也要取到小數後兩位(助教更正:不用取到小數後兩位,取整數就好) Q: 想確認一下,後面的%是指還剩多少空間可以用的%數,還是已經用了多少空間的%數?( ( available/total ) or ( (total-available)/total) ) A: 前者吧 ## 2 ID3 Editor Q: `usage: hw0502 -[tTaAycg] "value" file1 [file2...]` ` hw0502 -d file1 [file2...]` ` hw0502 -l file1 [file2...]` [file2...] 的意思是一次有可能輸入多個音檔嗎?(有上限嗎?) A: 會有多個音檔,上限為十個檔案 Q: 需要考慮擴展標籤嗎? A: 不用 Q: `-l` 的情況下,裡如果後面的檔案沒有 ID3 的資料的話,要怎麼顯示? A: 就诶個 message 說沒有 ID3 tag 就好 Q: 我是否可以要求使用者一次執行只能使用一種 `option`? A: 好 Q: 如果參數同時出現-d -l -h 一樣是以最後出現的為準嗎? A: 第二題我保證一次只有一個 option Q: 更改 tag 時,如果沒有 ID3 的資料,我們是要自己新增還是報錯? A: 新增好了 Q: 想問問學長如果我想要刪除檔案的部分資料應該怎麼做?之前好像都是複製一份新的檔案,然後重新塞進去新的,但感覺很沒意義,是否有更好的方法嗎? A: 這我沒想過ㄟ,一時間也沒想到好方法,可以問問看老師 (續上題 Q: 在第二題有一個 `-d Deletes an ID3 tag` 的 option,但所謂刪除是指要將整個 ID3 tag 資料刪除還是將所有資料清空只留標頭 `TAG` 呢? 然後如果說要刪除檔案,之前教的幾乎都是新開一個檔案然後全部複製進去,似乎沒有講過如果我只想刪除部分資料時該怎麼處理?老師有甚麼建議的方法嗎? > 我當初在出題的時候 > 是想要把整個 tag 刪除 > 當然是要包含 "TAG" 囉 > > 你有用過 MS Word 吧 > 你應該知道 > 當你在操作 Word 的時候 > 其實他只會操作在一個「暫存檔」 > 之後再覆蓋掉原本的檔案 > 所以有幾個做法 > a) 先讀取原本的檔案 > 寫到新的檔案 > 之後再重新命名回原本的檔案 > b) 把原來的檔案讀成 structure > 修改後再寫回去 > > 大概不出這些做法吧 > [name=L紀] <!-- https://stackoverflow.com/questions/873454/how-to-truncate-a-file-in-c --> <!-- 話說 w 開本來就會直接覆蓋掉了不是嗎? --> <!-- 可是我問到的是清空耶怎麼辦--> Q:在 -d 這個 option 的功能是 Deletes an ID3 tag 所以我把 Title、Artist、Album、Year、Genre、Comment、Track 都設為0 但是 Genre 0 是藍調 所以我 -l 出來會變這樣 test2.mp3: Title: Artist: Album: Year: Genre: Blues (0) Comment: Track: 0 Q1: 如果原本要印文字的地方值是 NULL ,可不可以像上面一樣,什麼都不印? Q2: Genre 的部分 值初始化設成 0 嗎?還是要特別設成 255 ?(255是undefined 的意思) Q3: Track 超過255是否可以報錯直接結束程式? A:在ID3v1中,如果要把genre設成unknown通常會把其設為255。 A1:可以寫None, Unknown, Undefined或留空都可以,請註明在README A2:初始化成255 A3:要報錯並維持原值不改 Q: genre>79 且不等於255 要報錯嗎?? A:genre > 79 && != 255 要報錯 Q:genre > 79 && != 255 要報錯,這件事是指在列出或刪除tag,以及修改任一屬性時,如果發現原本的gerne格式不對,都要直接報錯並結束嗎? A:其他操作就不用考慮了 Q:zero-byte為0時,欲修改的comment,參數長度超過28,要判錯嗎? A:應該是 track 有值、zero-byte 為 0 時長度超過 28 要報錯 Q:zero-byte不為0時,欲新增track,要判錯嗎? A:zero-byte不為0時,欲新增track,要判錯 Q:如果原本comment長度是29 or 30,現在我用-c修改comment,且修改後的comment長度<=28,則我該把zero-byte設為0且track設為0嗎? A:我覺得是要但我不會測 ## 3 Base64 Q:執行結果要和base64指令的結果完全一樣嗎? A:內容跟 base64 一樣就好 (base64 應該不會做啥奇怪的事吧?), Q:base64這個指令 如果沒有加上--wrap=0 會每76個字自動換行 這樣的話 我們也要跟他一樣換行嗎? A:不用換行 Q:有規定明文副檔名一定要是.txt嗎? A:不限定副檔名 Q:第三題有可能-e -d同時存在嗎? A:不會喔 ## 4 Taiwanese Learner <details> <summary>題目敘述</summary> # Taiwanese Learner Taiwanese, also known as Taiwanese Hokkien, Taigi, 臺語, 臺灣閩南語, is a variety of the Hokkien language spoken natively by about 70%+ of the population of Taiwan. However, due to the 國語運動 implemented before, less and less people use this language nowadays. Although there are some native language courses in schools, they are far from enough, most young people don't use Taiwanese in their life, and most people don't know how to write down Taiwanese, they even think Taiwanese don't have a writing system. In fact, Taiwanese has a well-structured writing system. It can be both written in Hàn-jī (漢字) and Tâi-lô phing-im (臺羅拼音). "Tâi-lô phing-im" is an example of 臺羅拼音, a word seperated by '-' or ' ' represent a 漢字, the symbol above a word represent it's tone. Today, TA A-huâ (阿華) wants a tool to help him pronounce Taiwanese. The tool will take a sentance of 臺羅拼音 as input which has a maximum length of 50, then generate a sentance and a single .wav file that contains the pronounation of each words seperately and then the whole sentance. As for input, because the tones' symbols of them are not presented in ASCII (e.g.: â, o̍), we will use numbers to represent tones instead. Taiwanese has 8 tones, so we will use number 1~8. For example, Tâi-lô phing-im will be represented as Tai5-lo5 phing1-im1. Input's tones always represent as numbers. After taking the input, the tool will use a web API to download the pronunciation from Internet. (Tip: you can use Unix commands like `curl` or `wget`) This is a website that help you pronounce Taiwaness: `https://suisiann.ithuan.tw/講` This is the web API to download the pronounation: `https://hapsing.ithuan.tw/bangtsam?taibun=<input>` For example, if you want the pronounation of Guá-sī tâi-uân-lâng (我是臺灣人), you can use: `https://hapsing.ithuan.tw/bangtsam?taibun=Gua2-si7+tai5-uan5-lang5` and get 1 .wav file (Tip: replace space with '+' in the url, spaces can cause some problems) Apart from the whole sentence, you also need to grab the pronounation of each words from the sentence. Beware, Taiwanese has something called Liân-tho̍k piàn-tiāu (連讀變調), that means when pronouncing a sentance, except for **the last word in the sentence**, all other words need to change their tones while keeping their tones' numbers the same. But when you grab a word from a sentance and pronouce it alone, you also need to change it's tone's number, so it can retain it's tone. To make it simpler, TA A-huâ provided simplfied rules of 連讀變調 in **tone.pdf**. For example, "Gua2-si7 tai5-uan5-lang5" will become "Gua1. si3. tai7. uan7. lang5.". You need to use the API for these 5 words separately ("Gua1.", "si3.", "tai7.", "uan7.", "lang5.") and get 5 .wav files. After that, you need to combine those 6 (5 seperated words and 1 full sentance) .wav files into 1 .wav file called **out.wav**, you can check .wav file format in Wiki. So if you input `Gua2-si7 tai5-uan5-lang5.`: ```bash $ ./hw0505 input: Gua2-si7 tai5-uan5-lang5. output: Gua1. si3. tai7. uan7. lang5. Gua2-si7 tai5-uan5-lang5. out.wav has been generated. ``` **out.wav** file will sound like `Gua1. si3. tai7. uan7. lang5. Gua2-si7 tai5-uan5-lang5.` In **out.wav**, the first half part should sound the same as the last half part. TA A-huâ also provided **example.wav** as the output file of it. Here is another example: ```bash $ ./hw0505 input: Gueh8-niu5. output: Gue3. niu5. Gueh8-niu5. out.wav has been generated. ``` The input will always be in correct 臺羅拼音 format, and will always consist of 1 sentence. That means it will only contain one dot, lower-case letters, one upper-case letter, non-continuous spaces, non-continuous dashes, non-continuous numbers. You also don't need to handle any error cases, like fail to create files, can't connect to Internet etc. You are allow to create temporary files in the same directory. TA A-huâ also provided **example.pdf**, which includes 臺羅拼音 sentances and their corresponding Tâi-gí hàn-jī (臺語漢字) and Huâ-gí huan-i̍k (華語翻譯). If you are interested in learning Taiwanese, you can take 閩南語概論 or 初級台語 courses in NTNU </details> <details> <summary>聲調說明</summary> # 聲調說明 ## 聲調類型 漢語的聲調初分為平、上、去、入四種,而後各自再分陰、陽,但各方言在語言演進的過程中,產生不同的狀況。今日臺灣通行的閩南語,陽上的調值已演變為和陽去是一樣的,因此共有七個聲調,分別是:陰平、陰上、陰去、陰入、陽平、陽去、陽入。舉例說明如下: | 調類 | 陰平 | 陰上 | 陰去 | 陰入 | 陽平 | (陽上) | 陽去 | 陽入 | | :----: | :---: | :---: | ----: | :--: | :---: | :----: | :---: | :--: | | 正式版 | tong | tóng | tòng | tok | tông | | tōng | to̍k | | 數字版 | tong1 | tong2 | tong3 | tok4 | tong5 | | tong7 | tok8 | | 例字 | 東 | 黨 | 棟 | 督 | 同 | (動) | 洞 | 毒 | ## 變調 在詞句中,閩南語有所謂「連讀變調」,即單字的語音會因為接了另一個字而改變聲調,使句中的字音與該單字的本調聽起來不同,而且這是一個必用規律,所接的字不限聲調為何,皆須變調。除了最後一個字之外,句中的每一個字都變調。變調規則大致為: | 聲調 | 變調規則 | 例詞 | 本調 | 變調後實際語音 | | :---: | :---------: | :--: | :---------: | :------------: | | 陰平1 | 1→7 | 心肝 | sim1-kuann1 | sim7-kuann1 | | 陰上2 | 2→1 | 小弟 | sio2-ti7 | sio1-ti7 | | 陰去3 | 3→2 | 世間 | se3-kan1 | se2-kan1 | | 陰入4 | 4→8(-p-t-k) | 出名 | tshut4-mia5 | tshut8-mia5 | | 陰入4 | 4→2(-h) | 鐵馬 | thih4-be2 | thi2-be2 | | 陽平5 | 5→7 | 來往 | lai5-ong2 | lai7-ong2 | | 陽去7 | 7→3 | 外口 | gua7-khau2 | gua3-khau2 | | 陽入8 | 8→4(-p-t-k) | 木瓜 | bok8-kue1 | bok4-kue1 | | 陽入8 | 8→3(-h) | 月娘 | gueh8-niu5 | gue3-niu5 | -p 的意思是該字以 p 結尾,-t, -k, -h 以此類推 </details> ## Bonus: What’s Wrong <style> @keyframes animation { 0% { transform: rotateY(-20deg); } 80% { transform: rotateY(20deg); } 100% { transform: rotateY(1820deg); } } </style>