--- title: 2021.01.12 期末考 題解 tags: 慈中, 109 期末考, 題解 --- # 2021.01.12 期末考 題解 <!-- 個人覺得難度排序:$A > E > B > D > C$ --> ## [A. ](https://tcshoj.tw/problem/1031) Author:`??` 本題題型:`??` **標程:[#](https://tcshoj.tw/submission/)** **驗題:[#](https://tcshoj.tw/submission/)** ## [B. 不要看我的密碼](https://tcshoj.tw/problem/1032) Author:`??` 本題題型:`字串搜尋` **標程:[#](https://tcshoj.tw/submission/)** **驗題:[#](https://tcshoj.tw/submission/)** **解法:** 先比對每個字串裡的字,之後假如錯誤就停止判斷,正確其輸出 **CORRECT** ```cpp while(realpass[j] == shitpass[i+j]) ``` **正確 Code:** ```cpp // Ans 1 (strstr) #include<bits/stdc++.h> using namespace std; #define LENGTH 500 int main(){ char search[LENGTH],source[LENGTH]; cin>>search>>source; char *mix = strstr(source, search); if (mix == NULL) { cout<<"ERROR"; } else { cout<<"CORRECT"; } return 0; } // Ans 2 (Find) #include <bits/stdc++.h> using namespace std; int main() { string realPass = "", shitPiece = ""; cin >> realPass >> shitPiece; int check = shitPiece.find(realPass); if (check >= 0) cout << "CORRECT"; else cout << "ERROR"; return 0; } // Ans 3 ([i]==) #include <bits/stdc++.h> using namespace std; int main() { string realPass = "", shitPiece = "", tempSTR = ""; cin >> realPass >> shitPiece; shitPiece += " "; for(int i = 0; i < shitPiece.size(); i++){ tempSTR = ""; int j = 0; while(realPass[j] == shitPiece[i+j]){ tempSTR += shitPiece[i+j]; j++; } if(realPass == tempSTR){ cout << "CORRECT"; return 0; } } cout << "ERROR"; return 0; } // Ans 4 (Fixed) #include <bits/stdc++.h> using namespace std; int main(){ string pw, rand; cin >> pw >> rand; for (int i = 0; i < rand.size(); i++){ int j = 0; do{ if(j+1 == pw.size()){ cout << "CORRECT"; return 0; } j++; }while (pw[j] == rand [i+j]); } cout << "ERROR"; } ``` ## [C. ](https://tcshoj.tw/problem/1033) 本題題型:`??` <!-- 本題靈感來源:[Codeforces Round #573 (Div. 2) pA](https://codeforces.com/contest/1191/problem/A) --> **標程:[#](https://tcshoj.tw/submission/)** **驗題 :[#](https://tcshoj.tw/submission/)** ## [D. 聖糕難望](https://tcshoj.tw/problem/1034) Author:`??` 本題題型:`SCANf特殊輸入、時間加減` **標程:** ```c++ #include <bits/stdc++.h> using namespace std; int main(){ int n; cin >> n; for(int i = 0; i < n;i++){ int MON=0, sDD=0, sHH=0, sMM=0, eMON=0, eDD=0, eHH=0, eMM=0, sTime, eTime, fTime; scanf("%d/%d.%d:%d", &MON, &sDD, &sHH, &sMM); // scanf 格式化輸入 scanf("%d/%d.%d:%d", &MON, &eDD, &eHH, &eMM); //scanf 格式化輸入 sTime = ((((sDD * 24) + sHH ) * 60) + sMM); // 轉換為分鐘 eTime = ((((eDD * 24) + eHH ) * 60) + eMM); // 轉換為分鐘 fTime = eTime - sTime; // 判斷是否超過一天 if (fTime < 1440) { //1440 為一天的時間(分鐘) cout << (fTime / 60) << " 還不能吃蛋糕喔 "; fTime = 1440 - fTime; cout << setw(2) << setfill('0') << fTime / 60 << ":" << setw(2) << setfill('0') << fTime - (fTime / 60) * 60 << "\n"; } else { cout << (fTime / 60) << " 向上行三問訊禮 "; fTime = fTime - 1440; cout << setw(2) << setfill('0') << fTime / 60 << ":" << setw(2) << setfill('0') << fTime - (fTime / 60) * 60 << "\n"; } // C++ // setw() 和 setfill() 可補上0 // setw 是下一個字元要幾格 // setfill 設定空白地方補上甚麼 // C // printf("%02d",x); // 或是用 if // if(fMM/60 < 10){ // cout << "0"; // } cout << fMM/60 << ":"; } } ``` ## [E. ](https://tcshoj.tw/problem/1035) Author:`??` 本題題型:`??` **標程:[#](https://tcshoj.tw/submission/)** ## 結語