1. 下載好 .ova 檔
2. 右鍵點選該檔案 -> 開啟檔案 -> 選擇 VirtualBox
(或打開VirtualBox -> 檔案 -> 匯入應用裝置)
3. 匯入即可
可能遇到的錯誤:
E_INVALIDARG 0x80070057
這表示空間不夠了,請清出足夠的空間。
E_FAIL (0x80004005) MachineWrap
嘗試重開機看看。
1. 下載好 .ova 檔
2. 右鍵點選該檔案 -> 開啟檔案 -> 選擇 VirtualBox
(或打開VirtualBox -> 檔案 -> 匯入應用裝置)
3. 匯入即可
可能遇到的錯誤:
E_INVALIDARG 0x80070057
這表示空間不夠了,請清出足夠的空間。
E_FAIL (0x80004005) MachineWrap
嘗試重開機看看。
#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; }
解題心得
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; }
程式碼
#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; }
程式碼
#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; }
解題心得:
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; }
題目簡介
請根據使用者輸入的命令,模擬圖書資料庫,並做出相對應的操作。
指令如下:
(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"
解題心得:
此處的解題紀錄"排在前面"的資料代表時間"越晚"
程式碼:
#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; }
解題心得:
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; }
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. 沒有錯誤訊息就成功!輸出檔會生成在同一個目錄底下。
程式碼:
#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; }