From 3e2c0c1c6f598a4a45ccd2b9881deb4ad89bcd8e Mon Sep 17 00:00:00 2001 From: Huang Date: Mon, 21 Jun 2021 19:18:13 +0800 Subject: [PATCH 1/2] =?UTF-8?q?add=20IG=20=E8=B2=BC=E6=96=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 755433/20210617_homework.cpp | 92 ++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 755433/20210617_homework.cpp diff --git a/755433/20210617_homework.cpp b/755433/20210617_homework.cpp new file mode 100644 index 0000000..0190554 --- /dev/null +++ b/755433/20210617_homework.cpp @@ -0,0 +1,92 @@ +#include +#include +#include +using namespace std; + +bool WritePaste(); +void PostPaste(); +void passedtime(int StopTime); + +struct paste { + string user; + string picture; + string content; + int time; +}; + +paste post, NewArticle; +stack article; +int StopPost; + + +int main() { + system("clear"); + cout << "!歡迎來到小克車的社群網站!" << endl; + cout << "接下來是 PO 文階段" << endl; + cout << "----------------------------" << endl; + + bool YNpost = true; + + while (YNpost) { //輸入階段 + YNpost = WritePaste(); + } + + while (! article.empty()) { //輸出階段 + PostPaste(); + } +} + + +bool WritePaste() { + cout << "請輸入你的 ID (輸入 0 表示結束):"; + cin >> NewArticle.user; + + if (NewArticle.user == "0") { + cout << "---------我是分隔線---------" << endl; + return false; + } + + cout << "圖片網址:" << endl; + cin >> NewArticle.picture; + + cout << "輸入內文:" << endl; + cin >> NewArticle.content; + + cout << "----------------------------" << endl; + + NewArticle.time = time(NULL); + article.push(NewArticle); + return true; +} + +void PostPaste() { + StopPost = time(NULL); + post = article.top(); + + cout << "名稱:"; + cout << post.user << endl; + + cout << "圖片:" << endl; + cout << post.picture << endl; + + cout << "內文:" << endl; + cout << post.content << endl; + passedtime(StopPost); + cout << "-------------" << endl; + + article.pop(); +} + +void passedtime(int StopTime) { // po 文時間 + int pass = StopTime - post.time; + + if (pass == 0) { + cout << "剛剛\n"; + } else if (pass >= 60 && pass < 3600) { + cout << pass / 60 << "分鐘前\n"; + } else if (pass >= 3600) { // 等等...不會有人跑這個程式花幾個小時吧?.? + cout << pass / 3600 << "小時前\n"; + } else { // 我就不用寫超過一天的吧OuO + cout << pass << "秒前\n"; + } +} From 4f3c44ed10bdd4bd49a3dde4b234d509ca922eae Mon Sep 17 00:00:00 2001 From: Huang Date: Tue, 22 Jun 2021 23:44:05 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix=20struct=20=E5=85=A7=E7=9A=84=E8=AE=8A?= =?UTF-8?q?=E6=95=B8=E6=8E=92=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 755433/20210617_homework.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/755433/20210617_homework.cpp b/755433/20210617_homework.cpp index 0190554..ac31a3c 100644 --- a/755433/20210617_homework.cpp +++ b/755433/20210617_homework.cpp @@ -8,10 +8,10 @@ void PostPaste(); void passedtime(int StopTime); struct paste { - string user; - string picture; - string content; - int time; + string user; + string picture; + string content; + int time; }; paste post, NewArticle;