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: 自斷退路、破釜沉舟
(網路上這句有很多不同的翻譯,這裡選一個順眼的: 用他破釜沉舟的意志)

2020年12月10日 星期四

【Wicked】popular 歌詞筆記

makeover: (個人形象的)改頭換面

take over: 接管

follow my lead: 跟著我

poise: 姿態(不確定歌詞裡的意思)

flounce: (為了吸引人注意)大步走動

fix my hair: 整理頭髮

cohort: 有共通點的(通常指年齡)一群人

awfully:非常、十分

dialysis: (醫學上對患者的)透析

pal: 朋友

dreary: 沉悶的、令人沮喪的

unprepossessing: 無趣乏味的

on their own behalf: 他們自己的行為上

shrewd: 精明的

clandestinely: 暗中的