2021年12月28日 星期二

看論文的網站

 https://arxiv.org/

通常比較新的paper可以在這裡找到。有時候論文從投稿到被接受可能長達一年,原因是流程繁瑣、被搞等等,總之為了避免在此期間有人搶先發表搶走credit,會在這裡先發。論文品質不一。

IEEE: conference跟journal上都是很好的論文

acm T開頭相關的都值得看(?)

google scholar可以看論文被引用過幾次、分別是哪篇


資安相關的conference可以參考:https://people.engr.tamu.edu/guofei/sec_conf_stat.htm

前面四個最頂,台灣人投上也沒幾個。


MobiCom、infocom是通訊領域的知名conference


選哪些paper報:

先從上面提到的那些來找論文,看被cite或reference。如果該篇論文的conference名氣小但很新,可能是技術剛發展,也許還是有看的價值;如果該篇論文舊(ex:三年前)、conference沒啥名氣而且cite數也不多,那基本上就不用看了,除非是競爭對手的文章,要研究他的動向(?)


因為時間精力有限,才要懂得從論文名字、摘要,或者引用等等來判斷論文需不需要讀。花幾周讀不重要的論文只是浪費時間。以及正因如此,才要在其他人報paper的時候吸收學習。

2021年10月21日 星期四

[loveless] 單字筆記

form-room: (中小)學生早晨接受點名的教室

sleepover: 過夜

word for word: 逐字的、一字不差的

truth or dare: 真心話大冒險

chorus: 異口同聲 

interject: 插話

outrage: 憤怒

drawl: 說話拉長音,說話拉長調子

cackle: 格格笑

berate: 斥責

mascara: 睫毛膏

smudge: (擦拭後留下的)汙跡,污痕

radiator: 暖氣裝置

ajar: 半開的

eyeful: 滿眼的

on and off: 間歇的

sparkly: 閃閃發光

knit: 針織

geriatric: 老年的

unfazed: 不為所動

slouch: 無精打埰地站(或坐、走)

orgy: (尤指縱情酒色或毒品的)狂歡聚會

eyelash: 睫毛

giddy: 頭暈

unbridled: 肆無忌憚

topple: 傾倒

numeracy: 算術

climbing frame: 攀爬架

leavers: 離校生

unscathed: 毫髮無損

commotion: 騷動

pull up: (某人)把車停下

sink in: (事實或想法)逐漸被完全理解,被充分意識到

slur: 含糊不清地說話

prod: (用手指、尖物等)刺,捅;戳

chastise: 責備

barrage: 接二連三的

boot: (汽車後部的)行李箱,後備箱

hideously: 極其

cobble: 鵝卵石

candid: 坦率

allegiance: 忠誠

get cracking: to start doing something quickly

fern: 蕨類

whoosh: 嗖的一聲;呼的一聲

splash of colour: https://hinative.com/zh-TW/questions/4147444

carpet: 地毯

mouldy: 發霉的

beige: 淺褐色

sash:(門窗上鑲玻璃的)窗框

meadow: 草地、牧場

fleece: 羊毛

duvet: 羽絨被

mumble: 咕噥

relegate: 貶謫

branch out: 涉足(尤指新工作);擴展(業務)

ramble: 語無倫次地閒扯;沒完沒了地胡亂說

slump: 沈重地坐下(或倒下)

stock photo: 供設計公司和廣告商即時使用的現成相片,通常是由想找些外快的業餘攝影師所拍攝。

fairy lights:(尤指聖誕樹上的)彩色小燈

shaggy: (毛髮)粗長而蓬亂的

give sth/sb the once-over: 對…草草檢查一下;對…走馬看花地看一遍

banter: 開玩笑

fluffy: 毛茸茸的、蓬鬆的

stan: 瘋狂追星

trot: 小跑

unerring: 永不犯錯的;一貫正確的

mingle:(在社交場合)相交往,相往來

posh: 高檔的

hook up: 勾搭、約炮

Matriculation: 大學入學 

sprawl: (懶散地)攤開四肢坐(或躺)

hallmark: 特點

fixation: 異常依戀,固戀;癖

joke aside: 言歸正傳,說正經的

ramble: 漫談

at length: 仔細的

headboard: 床頭板

oblivious: (尤指對周圍發生的事情)毫不在意的,毫無知覺的,未察覺的

jarring: 令人感到不快的;刺激(神經等)的

mundane: 世俗的;單調的;平凡的

slim: 苗條的

bomber jacket: 飛行夾克

tartan: 花呢格紋

enamel: 瓷釉

glitter: 閃光

confetti: 五彩紙屑

onlooker: 旁觀者

archaic: 古老的、過時的

nasty: 可惡的

make a face: 做鬼臉

unnerving: 令人不安的

barge: (魯莽地)衝,闖

under your breath: 低聲地,輕聲地

well up: https://hinative.com/zh-TW/questions/4698861

fiasco: 慘敗

vicinity: 附近

leer: (尤指男人)不懷好意地看,好色地看,色迷迷地看

dimple: 酒窩

amble: 漫步;緩行

woolly: 毛茸茸的

smutty: 淫穢下流

take aback: 大吃一驚

sort out: 解決、處理

fluster: 使心煩意亂;使緊張

banter: (善意地)取笑,逗弄

peppy: 精力充沛的,生氣勃勃的

hunch: 弓(背),彎腰

make a scene: 當眾吵鬧

wardrobe: 衣櫃

exude: 發散著

bagsy: 先說先佔權

crayon: 蠟筆

contender: 競爭者

grimly: 冷酷的

feud: 世仇

nudge: (尤指用肘部)輕推

reiterate: 重申

procure: 採購

sneak off: 偷偷跑走

crouch: 蹲伏

cape: 披肩

hanger: 衣架

bleary: 惺忪的

worn out: 精疲力盡

press-gang: 強迫

steadfastly: 堅定的

rummage: 翻找出

rucksack: 背包

reminisce: 回憶

anecdote: 奇聞軼事

snobbery: 勢利

falter: 衰弱;動搖;猶豫;畏縮

conjure: 變戲法

deadpan: 故作正經的

bicker: 鬥嘴

crux: 癥結

budge up:挪一挪;讓開

biscuit: 餅乾

cosiness: 舒適

pastel: 粉彩

lament: 哀嘆

dwindle: 縮小

shithead: 白癡、笨蛋

platonic: 柏拉圖式的

rundown: 詳細報告

blunt: 直率的;生硬的;直截了當的

chilling in: 放鬆

escapade:冒險行爲;尋求刺激的行爲;惡作劇

same difference: 差不多一樣

troupe: 劇團

commence: 開始

one-up: 勝過一籌

yikes:(表示驚訝、擔憂等)呀

rickety: 搖搖晃晃的

endearing:使人喜愛的

squawk: 發牢騷

ginormous: 巨大的

fire away: 儘管問吧

the worse for wear: (人)筋疲力盡的;(物品)破損不堪的,破舊的

call it a day: 結束工作;到此為止;收工

comfort food: (難過或焦慮時食用的)安慰食品,開心食品

get cold feet:(尤指面對結婚等重要事宜時)突然退縮,裹足不前

tag along: (通常指未經邀請)跟隨,尾隨

Glue At The Hip: (人)黏在一起

fed up with: 厭倦的;厭煩的;失望的

self-assured: 自信的

run into: 巧遇

sinister: 不祥的

nosy: 好管閒事的;愛打聽的

blink: 眨(眼睛)

ballpark: 大約估計

mingle: (在社交場合)相交往,相往來

bigot: 偏執的人,固執己見的人

trail off:(說話聲或類似聲響)逐漸減弱到停止,逐漸消失

scuff: 磨損,磨壞(尤指鞋或地板)

scrawl: 潦草地寫;亂塗

dance floor: (夜總會、餐館等的)舞池

go overboard: 做得過頭;過分激動;過分熱衷

snicker: 暗笑

transfixed: 呆若木雞

fast friend: 可靠的朋友

recoil: 畏縮

If x is anything to go by: 根據過去的經驗

bicker over: 為某事鬥嘴

deal breaker: 阻礙成功交易的關鍵因素

misogynist: 厭女者

abs: 腹肌

sludge: 汙泥

sincerity: 誠意

situate: 位於

crack a smile: to smile slightly

migraine: 偏頭痛

dumbfounded: 嚇得目瞪口呆的,驚得說不出話的

blurt: 脫口而出

nudge: 輕推

burglar: 入室竊賊

yank: 猛拉;猛拽

God forbid: 但願不會發生這事

teary: 哭泣的,流淚的

tear-stained: 淚濕的

wilt: 枯萎

drool: 流口水

zone out: 走神

salvage: 搶救

akin: 類似於

wistful: 惆悵的

foyer:(劇院、飯店等公共建築物入口處內的)門廳, (房子或公寓的)門廊

bouncy castle: 充氣城堡

fortitude: 堅毅

swimming pool noodles: 自行google吧

crutch: 拐杖

jab: 戳

beanbag: 懶骨頭

crux: 癥結

woe: 災難、不幸

clusterfuck: 大規模混亂;錯誤連連的災難性局面

you do you: Do what you want. Be yourself.

vape pen: 電子煙

snap: 厲聲說

nasty: 糟糕的;令人不快的,讓人討厭的

crack a joke: 講笑話

rip: 迅速扯開;猛力去除

clapback: (對批評或侮辱自己的人做出的)幽默回應,巧妙回擊

fathom: 弄清;理解

savoury: 鹹味的

rewind: 倒回(磁帶);倒(帶);倒(片)

damp: 潮濕

pester: 不斷煩擾,糾纏

life jacket: 救生衣

megaphone: 大聲公

dumbass: 蠢貨

bedhead:(因為剛起床)一頭亂髮


2021年9月23日 星期四

[Newsies] King of New York

matching: 適合的、相配的

box: 包廂

rye: 黑麥

nickle: 鎳幣

atcha: Slang for "at you"

lousy with: 有很多、充足的

stature: 地位、聲望

muckety mucks: 有地位、名聲的人(偏貶抑)

blow one's dough: 花光所有的錢

twirl: 轉、捻

barbershop: 理髮店

amscray: 閃開

poodle: 貴賓犬、奴才

fish out: 拖出

Flashpot: 閃光燈

highfalutin: 浮誇的

crap out: 使退場、出局

tapped out: 筋疲力盡

ditch: 丟棄、遺棄


本首歌使用大量當代的詞彙,有些生難字詞略過。

2021年9月13日 星期一

從code到encode/decode到base64

code

code,又稱碼。我們會把資訊用符號代替,這些符號就是碼。資訊科學常用到的是二元碼(binary code)

encode/decode

encode: 資訊 → 符號

decode: 符號 → 資訊

以ASCII為例,可以把字母轉換成相對應的數字(binary code)。

byte

一個byte用來儲存一個ASCII字元。

UTF-8

character to binary code

Base64

binary code to character


參考資料

https://web.ntnu.edu.tw/~algo/Code.html

看懂byte在幹嘛(python)

 假設我拿到了一個很長很長的byte sequence:
 b"*f\x97\xab&f-\x81ffff\x88f\xf67}@G\x06*\x97 \xab*6ff\xfe\x13\x0e\xebff\xbe\xeb\x81f[\x066\xec&\xee\xee\xfeI\xab\x97\xec\xc2\x06\x96\xa4P\xeb\xb9\x13\xfb\xebffff\xcbf/\x0f\x84f>\x0f\x0bf\xc2\x0f\x81\xa4\xe0\xebffff:6L\xabffff\xec\xecf\xcbffffffffffffffff\xecf\x0e\x93\x01fJ\x0b\xecf\xae\x93\x81f>\xbdffff%f+\xcb\x8efg\xee\x88ff\xcb*\xd3ff\x81f^\xbdffff\x15f+\xcb\x8ef\xe2\xee&f\x8e\xf1u\xec\x81\x11*e!f\x8ef\x97\xab*\xcb\x97fff\xc8\xf2\x8ef\x97\xab*\xcb\x97f\x88f\xf67\xfdSG\x06*\x97\xe0\xabl\xec\xc2\x06\x93f<\x0f\xa2f\x1a\x0fef\x05\x0f\xeefx\x0fLf\x8c\x0f\xf6f\xef\x0f\x0bfF\x0f\xcbf\x9e\x0f\x0b\xa4\xe0\xeb*\xbdJf*/\x97f\xecf\xef\x93\xecf\xe1\x93yf\x059:6L\xab\xec\xec\xcb\xee\xcbf\x9e\xeb\xabf\xcf\xcbfffftf\xd3\x0bffff\x93f<\xeb\xa2f\x1a\xebef\x05\xeb\xeefx\xebLf\x8c\xeb\xf6f\xef\xeb\x0bfF\xeb\x8ef\x97\xabNf\xc2\x06\x0b\xa4\xe0\xebffff:6L\xabffff\xcbf\x9e\xeb\x11f\xcf\xcbffff\x9af\xd3\x84ffff\xb1\xa4\xe0\xebffff:6L\xab*L\xd3\xad\xcbf\x9e\xebffff)\x13\xe0\xebffff:6L\xabffff\xcbf\x9e\xeb*L\xd3f\x86\xa4\xe0\xebffff:6L\xab:f\x88\xee\xcbf\x9e\xebffff\xd3\x13\xe0\xebffff:6L\xab*Lff\xe7\x13\xa4\xebffffff+\xbdffff\xd4\xech\x0bffff\xfd\xa4\xa4\xebffffff?"

該怎麼了解它呢?

首先,因為是byte,所以最前面有個b,並且字串頭尾被引號包起來。

再來會發現字串存在某種特殊pattern: 由斜線跟小寫字母x開頭,後面跟著兩個數字或字母組成的東西。

如果我們假設上面那串byte sequence叫做test,並且執行以下code:

for item in test:

    print(item)

會發現輸出好多整數。

奇怪,為什麼由字母、數字跟其他符號組成的字串,透過遍歷印出來,反而會得到整數數字呢?

所以我又撰寫以下code:

for i, item in enumerate(test):

    print("index {}: {} {}".format(i, test[i:(i+1)],item))

發現得到的輸出像是這樣:

index 0: b'*' 42
index 1: b'f' 102
index 2: b'\x97' 151
index 3: b'\xab' 171
index 4: b'&' 38
index 5: b'f' 102
index 6: b'-' 45
index 7: b'\x81' 129
index 8: b'f' 102
index 9: b'f' 102
index 10: b'f' 102
index 11: b'f' 102
index 12: b'\x88' 136
index 13: b'f' 102
index 14: b'\xf6' 246
index 15: b'7' 55

由於我們知道byte sequence嘛,顧名思義就是由一個個byte組成的長長一串,而byte本身就是以數字存在。上面的輸出結果表示對應的關係。

如果是\x開頭,代表是16進位,譬如 b'\x88' 就是16進位的byte,換算十進位則為136。

如果非\x開頭,對照ascii table會發現正好就是該字元與其ascii值對應。


參考文章

https://cloud.tencent.com/developer/article/1605567

2021年9月12日 星期日

[Newsies]Once and for All

once and for all: completely and finally

front-page: 頭版

snug: 舒適的

satin: 緞

thugs: 惡徒

slugs: (informal) 子彈

raise the stakes: 提高賭注、增加風險

brawl: 鬧事鬥毆

raring: 渴望急切的

sick of: 對...厭倦

play fair: to act in a fair and honest way

keep holding on: 不放棄

be gunning for: to often criticize someone or be trying to cause trouble for them

2021年9月11日 星期六

What is 'byte' in Python?

電腦以byte來儲存資料。

我們需要決定怎麼解讀byte,像是音樂、影像、文字等等使用的方法就不同,常見的有: PNG, JPG, ASCII, UTF-8。


在Python中byte string就是sequence of bytes,是人類讀不懂的。這麼做是為了把許多字元存起來。所以使用byte string前要先指定encode的方式,轉換成人類能夠理解的型態。

通常以b開頭,如: b'\xcf\x84o\xcf\x81\xce\xbdo\xcf\x82'

https://stackoverflow.com/questions/6224052/what-is-the-difference-between-a-string-and-a-byte-string


2021年9月9日 星期四

[Newsies] Seize the Day

seize the day: 把握當下

stare down: 以目光鎮懾某人

odds: 困難

battalion: (軍)營

Behold: 看

follow through: 堅持跟進

vow: 誓言

righted: 糾正 的過去式

draw near: 靠近

defiant: 挑釁的

All for one one for all: 我為人人 人人為我

Specs: 眼鏡

there'll be hell to pay: 會惹上大麻煩

2021年8月10日 星期二

no module named 'pandas' in jupyter notebook

結果才發現自己用 windows 的命令提示字元操作。最後關掉用 anaconda Prompt 重跑就沒問題了。

好像沒看到有人犯跟我一樣的神奇錯誤,故紀錄之。

2021年7月21日 星期三

nand2tetris 筆記總整理

blogspot 版本: 連結

HackMD 好讀版: 連結

github 作業: 連結

nand2tetris project4


D: data register

A: address / data register

M: the currently selected memory register: M = RAM[A]


結束程式:


(END)

    @END

    0;JMP

@+lowercase letter = variable

@+uppercase letter = label


virtual registers: R0, R1, R2…->大寫!


作業部分:

SCREEN大小為8192

用一個while(true)的loop去跑,有按就跑到WHITE(設值為0),不然就跑到BLACK(設值為1)

測fill記得要選no amination,不然怎麼跑都不會有結果。

nand2tetris project3

 project3

之前幾次作業都是combinational circuit,本周的sequential circuit會有out又接回來in的情形。


in=out是不被允許的,可能會有類似:「circle in connections」的錯誤訊息。需要另外拉一條線接回in,像是:out=feedback, in=feedback之類的。


Bit Chip會需要用到bulit-in 的DFF。


RAM要先用DMux把load訊號展開給更小的單元,最後在把資料Mux過。丟進去的address長度參考給定的規格,都是幾個高位元bit自己DMux&Mux會用到,剩下來的是給更小單元用的。


PC的實作順序,看coursera討論區有人提到似乎要以:inc, load, reset的順去去寫,不確定是否必要。最後要用Register來存資料,不能直接在reset的Mux16就寫out=out。討論區有助教留言說:「A common problem with this chip is that out=out should be from the Register chip.」(連結)


作業也是把a, b兩個資料夾的.hdl都壓縮成project3.zip上傳。

nand2tetris project2

 project2

要怎麼用HDL實現if-else語法呢?可以用上週作業寫過的Mux16。


Mux16會有兩個16-bit input,一個是原本的值,一個是符合條件後會變成的值,sel則是判斷的依據。


基本上可以想成:


if(sel)

    then b

else

    then a

zr要怎麼判斷呢?可以用上週作業的Or8Way兩次,如果兩個結果都為0就代表out為零。


幾個實作ALU會需要的語法:


b[0..15]=false // 輸入的第0~15 bit都為0

out[0..7]=low8, out[8..15]=high8, out[15]=signBit

// 把out的某些bit另外拿出來,之後要用來做其他判斷

nand2tetris project1

project1

實作projects/01裡面的15個.hdl檔,把它們打包成project1.zip,上傳到作業繳交區。


使用tools資料夾裡面的HardwareSimulator.bat,可以先用projects/demo裡面的Xor.hdl測試功能。


如果語法不正確會無法成功load chip,錯誤訊息會顯示在Hardware Simulator下方,值得注意的是有時候該區域會被擋住,如圖紅框所示:



如果實作結果與比對不符,會在比對過程中止,同樣會在紅框顯示第幾筆測試資料有誤。


如果自己測試.tst檔都沒問題,那麼繳交上去也能拿到全部分數。


可使用notepad++實作chip。過程中若要用到其他的chip,可以參考Hack Chip Set(https://drive.google.com/file/d/1IsDnH0t7q_Im491LQ7_5_ajV0CokRbwR/view)提供的API。

nand2tetris project0

project0

進入課程網站下載課程教材(https://www.nand2tetris.org/software),點選Download the Nand2tetris Software Suite。

裡面有兩個資料夾projects跟tools,選擇projects/00,把裡面的file.txt壓縮成project0.zip,上傳到作業繳交區即可。

2021年7月14日 星期三

nand2tetris project5

 本周作業花了不少時間才完成,因此決定寫篇筆記紀錄。

Memory

16384 -> 0100 0000 0000 0000

24576 -> 0110 0000 0000 0000

觀察可知,要區分RAM, Screen與Keyboard,可由13~14bit判斷:

00, 01 -> RAM

10 -> Screen

11 -> Keyboard

跟project3很像,先DMux分配load,之後再Mux

RAM, Screen, Keyboard的規格可以查Hack Chip Set,address根據容量大小而異。


測試時注意:


To anyone facing the same problem… on the Hardware Simulator user interface, right above where you see the script executing the tests, there are three drop down boxes. The one furthest to the right which is labeled “View” is probably currently set to “Script.” Click the drop down and select “Screen,” and you will see an interface that has a keyboard icon. Click it and then hit the corresponding key to complete the test. 

CPU

這部分最困難的是自行分析c,也就是各個元件的控制訊號該怎麼生成。


首先先從Mux16的c開始。我們知道instruction分為A instruction與C instruction,前者是把數字存放進A register,後者是進行運算。因此此處若為A instruction,Mux16就選擇instruction;若為C instruction,Mux16就選擇ALU output。

判斷指令直接看instruction[15]。

同理A register的c也是看instruction[15]。

writeM訊號指的是需不需要write back to memory。

觀察表格後,會發現d1是關鍵。因此若為C instruction且d1為1,則writeM為1,反之為0。

D register同樣觀察表格,發現與d2有關。因此若為C instruction且d2為1,則c為1,反之為0。

第二個Mux16是要選擇A register output或者inM。A instruction選擇前者,C instruction選擇後者這點應該不難理解。這裡需要參考下圖,發現要選A還是M由a,也就是instruction[12]控制。

ALU的c就是C instruction中c的部分。由第 11 bit 依序填入到第 6 bit即可。

最後是PC。沒想法的話就回去看課程網站提供的chip API或是chip的描述:
reset訊號已經有了,inc恆為true,怎麼生成load才是問題。當load==1,代表要把in讀進來,也就是說要jump。那甚麼時候要jump? 當然是條件有達成的時候。
觀察表格會發現,j1代表out < 0條件為真要jump,j2代表out=0條件為真要jump,j3代表out>0條件為真要jump。因此就看: (j1&ng) || (j2&zr) || (j3&(! (ng || zr)) ) 。

2021年7月10日 星期六

Hello!

nifty: 絕妙的

leave sth with sb: 把某物交給某人

peruse: 細讀

make things up: 無中生有、胡說八道

2021年7月9日 星期五

You and Me (But Mostly Me)

Heavenly Father: 天父

sidekick: 搭檔

aye aye: 是的船長!

side dish: 小菜

see eye to eye: 兩人意見一致

blow one's mind: 令人驚訝的

stick together: 互相扶持

psyched: 激動興奮的

2021年7月8日 星期四

Baptize Me

baptize 受洗

Pffttt 狀聲詞,有懷疑或不認同的意思

mission 佈道所

flutter: (心)蹦蹦亂跳

set free: 釋放

be through with: 中止、結束

stalling: 拖延

immersed: 受浸禮的

dowsed: 把....浸入水中

champ: 將軍

salvation: 救贖

went all the way: 做愛、全力以赴一氣呵成 (劇中雙關?)

Praise be to God: 讚美上帝

9. Palindrome Number

解題心得

1. 負數絕對不可能對稱

2. 不能用string,那就用int array紀錄

3. 比對只需要判斷一半的長度


class Solution {
public:
    bool isPalindrome(int x) {
        if (x < 0)
            return false;
        int arr[10] = { 0 }, count = 0, n = x;
        while (n > 0)
        {
            arr[count] = n % 10;
            n /= 10;
            count++;
        }
        for (int i = 0; i < count / 2; i++)
        {
            if (arr[i] != arr[count - i - 1])
                return false;
        }
        return true;

    }
};

Reverse Integer

解題心得

反轉數字本身很簡單。

只是怎麼處理overflow卡住。原本想說一開始先檢查或者翻轉後再檢查,但是有可能「原本數字不會overflow,但一翻轉就會」的情況。例如:123456789。
也因此只能在翻轉的過程中,一邊做一邊判斷。

判斷是否會overflow,就是乘以十倍後會不會超出214748364。參考int的範圍。
不過我的寫法有點取巧啦,剛好測資沒有測邊界值才AC吧~

class Solution {
public:
    int reverse(int x) {
        int ans = 0;
        while (x != 0)
        {
            if (abs(ans) > 214748364)
                return 0;
            ans = ans * 10 + x % 10;
            x /= 10;
        }
        return ans;
    }
};

2021年7月7日 星期三

Cannot source a directory: "$HOME/.vimrc"

missing-semester lecture03 Vim

Download our basic vimrc and save it to ~/.vimrc. Read through the well-commented file (using Vim!), and observe how Vim looks and behaves slightly differently with the new config.


一開始用:

mkdir ~/.vimrc

但是重開vim會出現錯誤訊息:「Cannot source a directory: "$HOME/.vimrc"」


用:

vi .vimrc

之後再把vimrc裡面的內容貼過去就解決了。


參考:

http://wiki.csie.ncku.edu.tw/vim/vimrc

2021年5月15日 星期六

以 VirtualBox 匯入 .ova檔

1. 下載好 .ova 檔

2. 右鍵點選該檔案 -> 開啟檔案 -> 選擇 VirtualBox

(或打開VirtualBox -> 檔案 -> 匯入應用裝置)

3. 匯入即可


可能遇到的錯誤:

E_INVALIDARG 0x80070057

這表示空間不夠了,請清出足夠的空間。



E_FAIL (0x80004005) MachineWrap

嘗試重開機看看。

2021年2月21日 星期日

a631: 11. LED Decoder

#include <iostream>
#include <map>
#include <string>
using namespace std;
map < string, char > tbl;

void init() {
	tbl["123457"] = 'A'; tbl["1234567"] = 'B'; tbl["456"] = 'C'; tbl["1580"] = 'D'; tbl["12456"] = 'E';
	tbl["1249"] = 'F'; tbl["12569"] = 'G'; tbl["13457"] = 'H'; tbl["37"] = 'I'; tbl["3567"] = 'J';
	tbl["13459"] = 'K'; tbl["156"] = 'L'; tbl["12357"] = 'M'; tbl["3579"] = 'N'; tbl["123567"] = 'O';
	tbl["1458"] = 'P'; tbl["12347"] = 'Q'; tbl["123459"] = 'R'; tbl["12467"] = 'S'; tbl["278"] = 'T';
	tbl["13567"] = 'U'; tbl["1379"] = 'V'; tbl["135790"] = 'W'; tbl["90"] = 'X'; tbl["1347"] = 'Y';tbl["23456"] = 'Z';
}
int main()
{
	init();
	string s;
	while (getline(cin,s))
	{
		for (int i = 0; i < s.size(); i++)
		{
			if (isalpha(s[i]))
				cout << s[i];
			else if (s[i] == '0' || s[i] == ' ') cout << " ";
			else {
				string tmp;
				do {
					tmp += s[i];
					if (tbl.count(tmp))
						break;
					i++;
				} while (!isalpha(s[i]) && i < s.size());
				cout << tbl[tmp];
				
				if (isalpha(s[i]))
					cout << s[i];
			}
		}
		cout << endl;
	}
	return 0;
}

2021年2月19日 星期五

e907: 108 p9. 二進位制密碼驗證

解題心得
s.find() 若找不到子字串,回傳string::npos。

程式碼

#include <iostream>
#include <vector>
using namespace std;

vector<int> result;
void check(string s)
{
	int zero = 0, one = 0;
	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] != '0' && s[i] != '1')
		{
			result.push_back(1);
			break;
		}
	}
	if (s.size() < 8 || s.size() > 12)
		result.push_back(2);
	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] == '0') zero++;
		else if (s[i] == '1') one++;
	}
	if (zero < 2) result.push_back(3);
	if (one < 3) result.push_back(4);
	if (s.find("101") == string::npos) result.push_back(5);
}
int main()
{
	string password;
	cin >> password;
	check(password);
	if (result.size() == 0) cout << 0;
	else
	{
		for (int i = 0; i < result.size(); i++)
		{
			if (i == 0) cout << result[i];
			else cout << " " << result[i];
		}
	}
	return 0;
}

e925: pD. 學號檢查

程式碼

#include <iostream>
#include <vector>
using namespace std;

vector<string> code;
bool isValid(string ID)
{
	if (ID[0] != 'B') return false;
	if (!isdigit(ID[1]) || !isdigit(ID[2])) return false;
	if (!isdigit(ID[7]) || !isdigit(ID[8])) return false;
	string s = ID.substr(3, 4);
	for (int i = 0; i < code.size(); i++)
	{
		if (s == code[i])
			return true;
	}
	return false;
}
int main()
{
	int n, invalid = 0;
	cin >> n;
	string ID;
	while (n--)
	{
		string s;
		cin >> s;
		code.push_back(s);
	}
	for (int i = 0; i < 10; i++)
	{
		cin >> ID;
		if (isValid(ID))
			cout << "Y" << endl;
		else
			cout << "N" << endl, invalid++;
	}
	cout << invalid / 10.0;
	return 0;
}

d732: 二分搜尋法

 程式碼

#include <iostream>
using namespace std;
int search(int arr[], int len, int x)
{
	int left = 0, right = len - 1, mid = (left + right) / 2;
	while (1)
	{
		if (arr[mid] == x) return mid + 1;
		if (mid < 0 || mid >= len || left >= right) return 0;
		if (arr[mid] > x) right = mid - 1;
		else left = mid + 1;
		mid = (right + left) / 2;
	}
}
int main()
{
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	int n, k, x;
	cin >> n >> k;
	int* arr = new int[n];
	for (int i = 0; i < n; i++)
		cin >> arr[i];
	for (int i = 0; i < k; i++)
	{
		cin >> x;
		cout << search(arr, n, x) << endl;
	}
	return 0;
}

e788: b3.畢業典禮(Ceremony)

解題心得:
cmp的部分要注意一下。

程式碼:

#include <iostream>
#include <algorithm>
using namespace std;
struct Student {
	int order;
	string ID, name;
};
bool cmp(Student a, Student b)
{
	if (a.ID[8] != b.ID[8])
		return a.ID[8] < b.ID[8];
	else if (a.ID[0] != b.ID[0])
		return a.ID[0] < b.ID[0];
	else 
		return a.order<b.order;
}
int main()
{
	int n;
	cin >> n;
	Student* list = new Student[n];
	for (int i = 0; i < n; i++) {
		cin >> list[i].ID >> list[i].name;
		list[i].order = i;
	}
	sort(list, list + n, cmp);
	for (int i = 0; i < n; i++)
		cout << list[i].ID[8] << ": " << list[i].name << endl;
	return 0;
}

2021年2月17日 星期三

Q1--Library Database 解題筆記

題目簡介

請根據使用者輸入的命令,模擬圖書資料庫,並做出相對應的操作。

指令如下:

(1) Insert: Insert "title" "author" "edition"

(2) Delete Edition: Delete Edition "title" "author" "edition"

(3) Delete Book: Delete Book "title" "author"

(4) Find Book: Find Book "title" "author"

(5) Find Author: Find Author "author"

(6) Sort by Title: Sort by "title"

(7) Sort by Author: Sort by "author"


解題筆記

一、取得指令方法
輸入指令可大致分為兩部分,一部份是「什麼指令」,另一部份是「資訊」。
問題是指令沒辦法單純以空白切割,也不一定是一個字。

方法: 使用getline()分割字串。

string cmd;
while (getline(cin, cmd))
{
stringstream ss(cmd);
getline(ss, cmd, '\"');
                // ......
        }
如此一來,就能取得「命令」的部分,即cmd。



二、解析指令的方法
方法: cmd.substr(pos, n) == 字串,pos為字串比對起始點,n為長度。

如此可在不破壞字串的情況下得到資訊。



三、 map, pair, set, typedef 的細節

解題結構如下:
typedef pair<string, string> B_Info; // title, author
typedef map<B_Info, set<int>> Books;
Books database;

如此一來,就能使用pair, map, set的特性快速存取、修改。

map 跟 set 都有count(),用來檢查有沒有某個資料。

typedef pair<string, string> B_Info 的意思是把 pair<string, string> 叫做 B_Info,這樣後面就不用每次都打 pair<string, string>,比較易讀也節省時間。


四、遍歷資料的細節
像是在輸出 edition 時,是用 set iterator 跑的。那要如何指定說像是: 第一個或最後一個資料輸出長的不一樣呢?

沒辦法像一般可以: 
for(int i=0; i< m.size();i++)
{
    if(i==m.size()-1) // do something.....
}
但可以:
if(it==m.begin()) {}


五、 sort map
如果想把 map 依照指定順序排列該怎麼做?

struct cmpByStringLength {
    bool operator()(const std::string& a, const std::string& b) const {
        return a.length() < b.length();
    }
};

// ...
std::map<std::string, std::string, cmpByStringLength> myMap;



心得

在「預期解題時間」一欄,助教寫了35分鐘。我真心好奇助教是如何計算時間的,感覺光是照著最後寫出來的code打也要半個小時左右,考場上不能查資料、重無到有寫出來,大一學生總得要一個多小時吧。(還是我程度太差?)

2021年2月10日 星期三

d566: 秒殺率

解題心得:
此處的解題紀錄"排在前面"的資料代表時間"越晚"

程式碼:

#include <iostream>
#include <vector>
using namespace std;

struct user {
	string name, status, first_status;
};
int main()
{
	int n, ac = 0, totalAC = 0;
	vector<user> database;
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	cin >> n;
	while (n--)
	{
		bool isExist = false;
		string n_tmp, s_tmp;
		cin >> n_tmp >> s_tmp;
		for (int i = 0; i < database.size(); i++)
		{
			if (database[i].name == n_tmp)
			{
				isExist = true;
				database[i].first_status = s_tmp;
				if(s_tmp=="AC")
					database[i].status = s_tmp;
				break;
			}
		}
		if (!isExist)
		{
			user tmp;
			tmp.name = n_tmp;
			tmp.status = tmp.first_status = s_tmp;
			database.push_back(tmp);
		}
	}
	for (int i = 0; i < database.size(); i++)
	{
		if (database[i].status == "AC")
			totalAC++;
		if (database[i].first_status == "AC")
			ac++;
	}
	cout << (double)ac / totalAC * 100 << "%" << endl;
	return 0;
}

2021年2月9日 星期二

f634: 士兵歸來

解題心得:
https://codist.me/zh/blog/stl-set/

程式碼:

#include <iostream>
#include <set>
#include <iomanip>
using namespace std;

struct soldier
{
	string name;
	int type, rank;
	bool operator<(const soldier &right) const
	{
		if (name != right.name)
			return name < right.name;
		else
		{
			if (type != right.type)
				return type < right.type;
			else
				return rank < right.rank;
		}
	}
};
int main()
{
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	int n, m;
	cin >> n >> m;
	set<soldier> legion;
	while (m--)
	{
		soldier tmp;
		cin >> tmp.name >> tmp.type >> tmp.rank;
		legion.insert(tmp);
	}
	int navy = 0, army = 0, air = 0, officer = 0, sergeant = 0, soldier = 0;
	for (auto it = legion.begin(); it != legion.end(); it++)
	{
		if ((*it).type == 1) navy++;
		if ((*it).type == 2) army++;
		if ((*it).type == 3) air++;
		if ((*it).rank == 1) officer++;
		if ((*it).rank == 2) sergeant++;
		if ((*it).rank == 3) soldier++;
	}
	cout << "navy:" << navy << " army:" << army << " air:" << air << endl;
	cout << "officer:" << officer << " sergeant:" << sergeant << " soldier:" << soldier << endl;
	cout << fixed << setprecision(1) << "survival rate: " << (double)legion.size() / n * 100 << "%";
	
	return 0;
}

2021年2月2日 星期二

在windows上使用opencc的方法

1. 從github下載專案並解壓縮

2. 用cmd切到專案資料夾的bin目錄下,同時把欲轉換的檔案也放入該目錄下

3. 輸入: opencc -i input.txt -o output.txt -c C:\Users\xxxxx\oooo\build\share\opencc\s2tw.json
-c 後面接指定的json檔路徑,至於哪個json檔依需求選擇。
-i 與 -o 後面接的檔案名稱好像需要為英文或繁中,簡中可能會讀不到

4. 沒有錯誤訊息就成功!輸出檔會生成在同一個目錄底下。

f266: Hello, Echo (Part 1)

程式碼:

#include <iostream>
#include <string>
using namespace std;

int main()
{
	string s[5];
	for (int i = 0; i < 5; i++)
		cin >> s[i];
	for (int i = 0; i < 5; i++)
	{
		for (int j = i; j < 5; j++)
			cout << s[j] << " ";
		cout << endl;
	}
	return 0;
}

2021年1月30日 星期六

a818: 1.解碼問題

 程式碼

#include <iostream>
using namespace std;
string decode(int len, int seq[], string s)
{
	string result = s;
	for (int i = 0; i < len; i++)
	{
		result[i] = s[seq[i] - 1];
	}
	return result;
}
int main()
{
	string s;
	int n, k;
	cin >> n;
	int* seq = new int[n + 1];
	for (int i = 0; i < n; i++)
		cin >> seq[i];
	cin >> s >> k;
	for (int i = 0; i < k; i++)
		s = decode(n, seq, s);
	cout << s;
	return 0;
}

virtual function

virtual function

在程式執行的時候才決定呼叫哪個function。

與一般的繼承class的function overload不同,如果一個function是virtual的,那麼在執行的時候會去判斷物件屬於哪個class,然後呼叫該class定義的function。

如果base class裡宣告某function為virtual,那麼繼承的class的某function也為virtual,無需特別宣告。


Pure Virtual Functions

有時候base class可能還無法實作某些function,但又需要先把功能定義清楚,該怎麼辦呢?

這時候就用到純虛擬函式,它是沒有函式實體的。例:

virtual void Area()=0;

而所有繼承自base class的class都需要自己定義Area的內容。


如果一個class存在pure virtual function,那麼該class就是抽象類別,它不能於主程式中被宣告、使用。

也因此繼承它的class要自己override 這些 pure virtual function,不然也會被視為抽象類別,也一樣法把被使用。

2021年1月29日 星期五

c199: 爬山去(Hiking)-TOI練習賽y7m5-1

 程式碼

#include <iostream>
#include <vector>
using namespace std;

int main()
{
	int n;
	while (cin >> n)
	{
		int count = 0, top, tmp;
		vector<int> m;
		cin >> tmp;
		m.push_back(tmp);
		for (int i = 1; i < n; i++)
		{
			cin >> tmp;
			if (tmp != m.back()) m.push_back(tmp);
		}
		for (int i = 1; i < m.size()-1; i++)
		{
			if (m[i - 1] < m[i] && m[i] > m[i + 1])
				count++;
		}
		cout << count << endl;
	}
	return 0;
}

2021年1月28日 星期四

f373: 週年慶 Anniversary

 程式碼:


#include <iostream>
using namespace std;

int main()
{
	int n, flag1, flag2;
	cin >> n;
	flag1 = n - (n / 2000) * 200;
	flag2 = n - (n / 1000) * 100;
	if (flag1 <= flag2) cout << flag1 << " 0";
	else cout << flag2 << " 1" << endl;
	return 0;
}

f441: 評分系統 Score

程式碼:

#include <iostream>
using namespace std;

int main()
{
	int n, points,studentN;
	cin >> n >> points;
	int* ans = new int[n];
	for (int i = 0; i < n; i++)
		cin >> ans[i];
	cin >> studentN;
	while (studentN--)
	{
		int score = 0, p;
		for (int i = 0; i < n; i++)
		{
			cin >> p;
			if (p == ans[i]) score += points;
		}
		cout << score << endl;
	}
}

2021年1月27日 星期三

2021年1月26日 星期二

e548: 11995 - I Can Guess the Data Structure!

程式碼

#include <iostream>
#include <stack>
#include <queue>
using namespace std;

int main()
{
	int n, x, command;
	while (cin >> n)
	{
		stack<int> st;
		queue<int> q;
		priority_queue<int> pq;
		bool isStack = true, isQueue = true, isPQ = true;
		while (n--)
		{
			cin >> command >> x;
			if (!isStack && !isQueue && !isPQ) continue;
			if (command == 1)
			{
				st.push(x); q.push(x); pq.push(x);
			}
			else
			{
				if (st.empty()||st.top() != x) isStack = false;
				if (q.empty()||q.front() != x) isQueue = false;
				if (pq.empty()||pq.top() != x) isPQ = false;
				st.pop(); q.pop(); pq.pop();
			}
		}
		if (!isStack && !isQueue && !isPQ) cout << "impossible" << endl;
		else if (isStack && !isQueue && !isPQ) cout << "stack" << endl;
		else if (!isStack && isQueue && !isPQ) cout << "queue" << endl;
		else if (!isStack && !isQueue && isPQ) cout << "priority queue" << endl;
		else cout << "not sure" << endl;
	}
	return 0;
}

【Come From Away】Stop the World

pinch yourself: 掐自己一下(表示某事太好或太奇怪,簡直令人難以置信)
lookout: 觀景處
take the time: 花費力氣(做某事)


virtual base class

使用時機
當一個class繼承自不同的多個class時,會繼承到他們的資料定義。這時可能會有重複的資料被繼承到,造成運作不符合預期,例如:

#include <iostream>
using namespace std;

class CA //common base class of CB and CC
{
public:
	int x;
	CA(int a = 0) { x = a; }
};
class CB :public CA
{
public:
	int y;
	CB(int a = 0, int b = 0) :CA(a) { y = b; }
};
class CC :public CA
{
public:
	int z;
	CC(int a = 0, int b = 0) :CA(a) { z = b; }
};
class CD : public CB, public CC
{
public:
	int w;
	CD(int a = 0, int b = 0, int c = 0, int d = 0 ,int e = 0) :CB(a, b), CC(c, d) {
		w = e;
	}
	void ShowVal() {
		cout << "x = " << CB::x << " y = " << y
		<< " x = " << CC::x << " z = " << z;
		cout << " w = " << w  << endl;
	}
};
int main()
{
	CD obj(5, 4, 3, 2, 1);
	obj.ShowVal(); //what happens?
	return 0;
}

輸出為: x = 5 y = 4 x = 3 z = 2 w = 1

如果改以virtual 方式繼承,相同的資料只會用到同一塊記憶體。例如:

#include <iostream>
using namespace std;

class CA //common base class of CB and CC
{
public:
	int x;
	CA(int a = 0) { x = a; }
};
class CB : virtual public CA
{
public:
	int y;
	CB(int a = 0, int b = 0) :CA(a) { y = b; }
};
class CC : virtual public CA
{
public:
	int z;
	CC(int a = 0, int b = 0) :CA(a) { z = b; }
};
class CD : public CB, public CC
{
public:
	int w;
	CD(int a = 0, int b = 0, int c = 0, int d = 0
		,int e = 0) : CA(a), CB(a, b), CC(c, d) {
		w = e;
	}
	void ShowVal() {
		cout << "x = " << CB::x << " y = " << y
		<< " x = " << CC::x << " z = " << z;
		cout << " w = " << w << " x = " << x << endl;
	}
};
int main()
{
	CD obj(5, 4, 3, 2, 1);
	obj.ShowVal(); //what happens?
	return 0;
}

輸出為: x = 5 y = 4 x = 5 z = 2 w = 1 x = 5


呼叫順序

constructors
first, virtual base classes in declaration order
then, other base classes in declaration order

destructors
 in the reverse order of the constructors

2021年1月25日 星期一

f277: 嘿嘿想不到吧

程式碼

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

class Student
{
public:
	string name, sentence;
	int _class, index;
};
bool cmp(Student s1, Student s2)
{
	if (s1._class < s2._class) return true;
	if (s1._class > s2._class) return false;
	if (s1.index < s2.index) return true;
	else return false;
}
int main()
{
	int n;
	while (cin >> n)
	{
		vector<Student> school;
		for (int i = 0; i < n; i++)
		{
			Student tmp;
			cin >> tmp.name >> tmp._class >> tmp.index >> tmp.sentence;
			school.push_back(tmp);
		}
		sort(school.begin(), school.end(), cmp);
		for (int i = 0; i < school.size(); i++)
		{
			cout << school[i]._class << " " << school[i].index << " " << school[i].name << endl<< school[i].sentence;
			if (i != school.size() - 1)cout << endl;
		}
	}
	return 0;
}

【Matilda】revolting children

revolt: 反抗、反叛
Get the best of sb: 被某人(負面)影響
chokey: 禁閉室
bar: 鐵欄杆
horde: 一群人
chalk: 粉筆

2021年1月22日 星期五

【Come From Away】On The Edge

jumping at our own shadows: 易受驚嚇的
suppertime: 晚餐時間
I beg your pardon: 不好意思、能再重說一次嗎?
airspace: 領空
torn up: 磨損
debris: 碎屑
asphalt: 柏油
landfall: 登陸
crack: 身心疲憊、精神崩潰
chilli: 辣味肉豆

2021年1月21日 星期四

【Come From Away】38 Planes (Reprise) / Somewhere in the Middle of Nowhere

pick up: 增加
turbulence: 不穩定氣流、顛簸
canoodle: 親熱
pace: 步調
seat back: 座椅靠背
tray table: (可折攏的)餐桌
taxiing: 滑行


2021年1月20日 星期三

【Come From Away】Me and the Sky

pilot: 飛行員
mortician: 殯葬業者
lift off: 起飛
charter: 包機
grab a drink: 喝一杯
think highly of: 認為...很了不起、對...評價很高
stay grounded: 雙關: 1)務實、腳踏實地  2)字面上的待在地上
air-to-air: 空對空的

2021年1月19日 星期二

【Come From Away】Finale

inlet: 海灣
bay: 海灣
nothing goes as planned: 事與願違
fella: 夥計們
cockpit: 駕駛艙
long distance relationship: 異地戀
northeast tip: 東北角
commemorate: 紀念、緬懷
Atlantic: 大西洋的
cod: 鱈魚
kettle: 開水壺
cove: 小海灣
sun is setting: 日落

f377: 運算式轉換

解題心得:
注意優先順序。

程式碼:

#include <iostream>
#include <string>
#include <sstream>
#include <stack>
using namespace std;
int priority(char c)
{
	if (c == '*' || c == '/') return 0;
	if (c == '+' || c == '-') return 1;
	else return 2;
}
int main()
{
	string s;
	while (getline(cin, s))
	{
		stringstream ss(s);
		stack<char> st;
		st.push('(');
		s += ")";
		for (int l = 0; l < s.size(); l++)
		{
			if (s[l] == ' ') continue;
			if (s[l] == '(') st.push('(');
			else if (s[l] == ')')
			{
				while (st.top() != '(')
				{
					cout << st.top() << " ";
					st.pop();
				}
				st.pop();
			}
			else if ('a' <= s[l] && s[l] <= 'z')
			{
				cout << s[l] << " ";
			}
			else
			{
				while (priority(st.top()) <= priority(s[l]))
				{
					cout << st.top() << " ";
					st.pop();
				}
				st.push(s[l]);
			}
		}
		while (!st.empty())
		{
			cout << st.top() << " ";
			st.pop();
		}
		cout << endl;
	}
	return 0;
}

2021年1月18日 星期一

f498: Heap

解題心得:
就.....資料結構實作。
參考文章:Min Heap and Max Heap Implementation in C++

程式碼:

#include<iostream>
using namespace std;
class maxHeap
{
public:
	maxHeap()
	{
		size = 0;
		for (int i = 0; i < 1025; i++) arr[i] = 0;
	}
	int arr[1025];
	int size;
	int parent(int i) { return (i - 1) / 2; }
	int find_left(int i) { return 2 * i + 1; }
	int find_right(int i) { return 2 * i + 2; }
	int getSize() { return size; }
	bool isEmpty() { return size == 0; }

	void heap_down(int i)
	{
		int left = find_left(i), right = find_right(i);
		int largest = i;

		if (left < this->size && arr[left] > arr[i])
			largest = left;
		if (right < this->size && arr[right] > arr[largest])
			largest = right;
		if (largest != i)
		{
			swap(arr[i], arr[largest]);
			heap_down(largest);
		}
	}
	void heap_up(int i)
	{
		if (i != 0 && arr[parent(i)] < arr[i])
		{
			swap(arr[i], arr[parent(i)]);
			heap_up(parent(i));
		}
	}
	void push(int n)
	{
		arr[this->size] = n;
		this->size++;
		heap_up(this->size - 1);
	}
	void pop()
	{
		arr[0] = arr[this->size - 1];
		this->size--;
		heap_down(0);
	}
	int top() { return arr[0]; }
};
class minHeap
{
public:
	minHeap()
	{ 
		size = 0;
		for (int i = 0; i < 1025; i++) arr[i] = 0;
	}
	int arr[1025];
	int size;
	int parent(int i) { return (i - 1) / 2; }
	int find_left(int i) { return 2*i + 1; }
	int find_right(int i) { return 2 * i + 2; }
	int getSize() { return size; }
	bool isEmpty() { return size == 0; }

	void heap_down(int i)
	{
		int left = find_left(i), right = find_right(i);
		int smallest = i;

		if (left < this->size && arr[left] < arr[i])
			smallest = left;
		if (right < this->size && arr[right] < arr[smallest])
			smallest = right;
		if (smallest != i)
		{
			swap(arr[i], arr[smallest]);
			heap_down(smallest);
		}
	}
	void heap_up(int i)
	{
		if (i != 0 && arr[parent(i)] > arr[i])
		{
			swap(arr[i], arr[parent(i)]);
			heap_up(parent(i));
		}
	}
	void push(int n)
	{
		arr[this->size] = n;
		this->size++;
		heap_up(this->size - 1);
	}
	void pop()
	{
		arr[0] = arr[this->size - 1];
		this->size--;
		heap_down(0);
	}
	int top() { return arr[0]; }
};
int main()
{
	int n;
	while (cin >> n)
	{
		minHeap heap1;
		maxHeap heap2;
		while (n--)
		{
			int num;
			cin >> num;
			heap1.push(num);
			heap2.push(num);
		}
		for (int i = 0; i < heap1.size; i++)
		{
			if (i != heap1.size-1) cout << heap1.arr[i] << " ";
			else cout << heap1.arr[i] << endl;
		}
		for (int i = 0; i < heap2.size; i++)
		{
			if (i != heap2.size - 1) cout << heap2.arr[i] << " ";
			else cout << heap2.arr[i] << endl;
		}
	}
	return 0;
}

【Matilda】School Song

put in effort: 盡力
heaps of: 很多
ancient history: 陳年舊事
for ages: 很久
living hell: 活受罪
peal:(鈴)大聲鳴響
listen up: something you say to make people listen to you (大家注意了、聽我這邊)
a thing or two: 一些事情、知識
step out of line: 行為不妥
speciality: 常做的事(?)
teacher's pet: 老師的寵兒

2021年1月17日 星期日

【Matilda】when i grow up

sweets: 甜食
square-eyed: 看電視上癮的
treats: 零食
take it on the chin: 毫無抱怨的承受

2021年1月16日 星期六

【Rent】I'll cover you

Don't got much baggage to lay at your feet: 不會為你帶來太多負擔
to spare: 有多的
lease: 租借
moat: 護城河
nickel: 五分美金
worn out: 筋疲力盡

2021年1月15日 星期五

【Rent】rent

breadline: 等候領取施捨食物的隊伍
eviction: 驅逐
chord: 和弦
sour note: 刺耳的音符
flue: 煙道
teeny: 很小的
crackle: 劈啪作響
incendiary: 能引起燃燒的
draw a line in the sand: 守住底線
make a stand: 進行抵抗
spar: 出擊
act tough: 來硬的
called their bluff: 質疑對方、挑戰對方

2021年1月14日 星期四

【Rent】one song glory

front man: 樂團主唱
have the world at one's feet: 極為成功
time flies: 時光飛逝
ring true: 聽起來像是真的
redeem: 贖回、挽救


2021年1月13日 星期三

【Rent】season of love 歌詞筆記

so dear: 多麼珍貴的
strife: 爭吵
burn one's bridge: 自斷退路、破釜沉舟
(網路上這句有很多不同的翻譯,這裡選一個順眼的: 用他破釜沉舟的意志)