From a793406ab7e80d69479fdf8f6f50dbf5996bb22e Mon Sep 17 00:00:00 2001 From: taynpg Date: Tue, 4 Mar 2025 10:57:45 +0800 Subject: [PATCH] =?UTF-8?q?add=EF=BC=9A=E6=B7=BB=E5=8A=A0=E5=B7=B2?= =?UTF-8?q?=E7=BF=BB=E8=AF=91=E8=BF=87=E5=86=85=E5=AE=B9=E7=9B=B4=E6=8E=A5?= =?UTF-8?q?=E5=8F=96=E5=80=BC=E5=8A=9F=E8=83=BD=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/settings.json | 22 +++++++++++++++++++++- handle.cpp | 1 + main.cpp | 17 ++++++++++++++--- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index ac0711c..2b3ea78 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -107,6 +107,26 @@ "span": "cpp", "valarray": "cpp", "variant": "cpp", - "xstring": "cpp" + "xstring": "cpp", + "chrono": "cpp", + "filesystem": "cpp", + "ios": "cpp", + "locale": "cpp", + "xfacet": "cpp", + "xhash": "cpp", + "xiosbase": "cpp", + "xlocale": "cpp", + "xlocbuf": "cpp", + "xlocinfo": "cpp", + "xlocmes": "cpp", + "xlocmon": "cpp", + "xlocnum": "cpp", + "xloctime": "cpp", + "xmemory": "cpp", + "xmemory0": "cpp", + "xstddef": "cpp", + "xtr1common": "cpp", + "xtree": "cpp", + "xutility": "cpp" } } \ No newline at end of file diff --git a/handle.cpp b/handle.cpp index 8ab59c8..8c587ba 100644 --- a/handle.cpp +++ b/handle.cpp @@ -4,6 +4,7 @@ #include #include #include +#include CHttpsHandle::CHttpsHandle() { diff --git a/main.cpp b/main.cpp index 70d8626..9886310 100644 --- a/main.cpp +++ b/main.cpp @@ -3,8 +3,9 @@ #include #include #include -#include #include +#include +#include // #include using json = nlohmann::json; @@ -59,6 +60,7 @@ int main(int argc, char* argv[]) auto trans_tool = std::make_shared(); trans_tool->set_id(base_info.appID, base_info.secretID); + std::unordered_map word_map; auto trans = [&](const std::string& words, std::string& out) -> bool { std::string request_url = base_info.baseUrl + trans_tool->combine(words, "auto", "en"); std::string response = https->sendGetRequest(request_url); @@ -81,13 +83,22 @@ int main(int argc, char* argv[]) continue; } std::string ret; - std::cout << "翻译:" << line << std::endl; + + if (word_map.count(line)) { + ret = word_map[line]; + vec.emplace_back(TResult{line, ret}); + continue; + } + if (!trans(line, ret)) { vec.emplace_back(TResult{line, "Failed"}); + word_map[line] = "Failed"; } else { vec.emplace_back(TResult{line, ret}); + word_map[line] = ret; } - std::this_thread::sleep_for(std::chrono::seconds(1)); + std::cout << "翻译:" << line << ", 结果:" << ret << std::endl; + std::this_thread::sleep_for(std::chrono::milliseconds(200)); } in.close();