# APCS實作2022-6 ## P1.cpp數字遊戲 參考 https://hackmd.io/@littleorange/apcs202206?fbclid=IwAR3FHVnplQ8IisYHfAtA0hV1xeUBWwmmEFmyLF5dE2HUxJ1dBb40Sxtkm8E 參考 https://hackmd.io/@thanksone/APCS20220612?fbclid=IwAR3Dms2d0E_EQo62eJdeHShrRXFn1G13HRVjwtuaQRZ1ZLHVR4jFI6U4-Jk 參考 https://yuihuang.com/zj-i399/ ```c++= #include <bits/stdc++.h> using namespace std; //2022-6 P1數字遊戲 //AC (2ms, 336KB) int main() {//參考https://yuihuang.com/zj-i399/ int a[10]= {0}; int mode=0; //眾數 int c=0; //眾數個數 for (int i=0; i<3; i++) { int n; cin >> n; a[n]++; if (a[n] > c) { mode = i; c = a[n]; } } cout << c; for (int i=9; i; i--) { if (a[i] >= 1) { cout << " " << i; } } return 0; } ``` ## P2.cpp字串解碼 感恩曹大大 參考 https://hackmd.io/@littleorange/apcs202206?fbclid=IwAR3FHVnplQ8IisYHfAtA0hV1xeUBWwmmEFmyLF5dE2HUxJ1dBb40Sxtkm8E 參考 https://hackmd.io/@thanksone/APCS20220612?fbclid=IwAR3Dms2d0E_EQo62eJdeHShrRXFn1G13HRVjwtuaQRZ1ZLHVR4jFI6U4-Jk 參考 https://yuihuang.com/zj-i400/ 14行plain有問題 只有60分 why ```c++= #include<bits/stdc++.h> //2022-6 P2字串解碼 參考 https://0rz.tw/PZ9ty using namespace std; int main() { int m,n; cin >> m >> n; vector<string> v(m); for(int i=0; i<m; i++) cin >> v[i]; string cipher; cin >> cipher; deque<char> c(cipher.begin(),cipher.end() ); deque<char> plain; //不知哪有問題 只有60分 for (int i=m-1; i>=0; i--) { int odd = 0; deque<char> p; for (int j=n-1; j>=0; j--) { if (v[i][j]=='1') odd++; if (v[i][j]=='0') p.push_front(c[j]); else p.push_back(c[j]); } if (odd%2) for (int j=0; j<n/2; j++) swap(p[j], p[n-n/2+j] ); plain= p; //用c=plain就100分 } for(char i : plain) cout << i; } ``` 100分 沒14行plain 把c當plain ```c++= #include<bits/stdc++.h> //2022-6 P2字串解碼 參考 https://0rz.tw/PZ9ty using namespace std; int main() { int m,n; cin >> m >> n; vector<string> v(m); for(int i=0; i<m; i++) cin >> v[i]; string cipher; cin >> cipher; deque<char> c(cipher.begin(),cipher.end() ); //deque<char> plain; //不知哪有問題 只有60分 for (int i=m-1; i>=0; i--) { int odd = 0; deque<char> p; for (int j=n-1; j>=0; j--) { if (v[i][j]=='1') odd++; if (v[i][j]=='0') p.push_front(c[j]); else p.push_back(c[j]); } if (odd%2) for (int j=0; j<n/2; j++) swap(p[j], p[n-n/2+j] ); c= p; //用c=plain就100分 } for(char i : c) cout << i; } ``` ![](https://i.imgur.com/XnrR4gi.png) ```c++= #include<bits/stdc++.h> using namespace std; //2022-6 P2字串解碼 參考 https://0rz.tw/PZ9ty // AC (6ms, 348KB) int main() { int m,n; cin >> m >> n; //m行0101 每行n個 vector<string> v(m);//裝0101 for(int i=0; i<m; i++) cin >> v[i]; //輸入m行 01010 string cipher; //裝ADJFIW 密文 cin >> cipher; deque<char> c(cipher.begin(),cipher.end() ); //裝密文 慢慢變成 明文 for (int i=m-1; i>=0; i--)//從最後一行0101開始 { int odd = 0; //1出現次數是odd就頭尾互換 deque<char> p; //裝明文 每次重製 位置很重要 //放錯會error: 'p' was not declared in this scope| for (int j=n-1; j>=0; j--)//從0101尾巴開始 { if (v[i][j]=='1') //計算1出現次數 odd++; if (v[i][j]=='0') //0把被切掉的頭放回頭 p.push_front(c[j]); else //1把被切掉的尾放回尾 p.push_back(c[j]); } if (odd%2) //1出現次數=奇數 for (int j=0; j<n/2; j++)//頭尾互換 swap(p[j], p[n-n/2+j] ); c = p;//確定轉換完成明文再丟進plain }//for外面 不認識p 用plain才能印 for(char i : c) cout << i; } ``` ## P3.cpp雷射測試 ## P4.cpp內積