# 所有程式碼 ## green judge ### 001 ```cpp= #include <iostream> using namespace std; int main() { cout<<"Hello!"; return 0; } ``` ### 002 ```cpp= #include <iostream> using namespace std; int main() { cout<<"This is a book."<<endl<<"That is a pen." <<endl<<"I am a student."<<endl; return 0; } ``` ### 003 ```cpp= #include <iostream> using namespace std; int main() { cout<<"^_^"<<endl<<"\"o\""<<endl<<"\\^o^/ "<<endl; return 0 ; } ``` ### 004 ```cpp= #include <iostream> using namespace std; int main() { int n; cin>> n; cout<<n+1911<<endl; return 0; } ``` ### 005 ```cpp= #include <iostream> using namespace std; int main() { int a; int b; int y; cin>> a>>b; y=a*b; cout<< y <<endl; return 0; } ``` ### 006 ```cpp= #include <iostream> using namespace std; int main() { int H; int M; cin >> H>>M; cout<<(H*60)+M<<endl; return 0; } ``` ### 007 ```cpp= #include <iostream> using namespace std; int main() { int M; cin>> M; cout<< (M/60)<<" "<<(M%60)<<endl; return 0; } ``` ### 008 ```cpp= #include <iostream> using namespace std; int main() { float c; float f; cin>> c; f=(c*9/5)+32; cout<< f; return 0; } ``` ### 009 ```cpp= #include <iostream> using namespace std; int main() { int a; int b; cin>>a; b=((a/11)*1000)+((a%11)*100); cout<< b; return 0; } ``` ### 010 ```cpp= #include <iostream> using namespace std; int main() { int G,g,b,p; cin>> g; G=g+3; b=(2*g)-5; p=((b/10)*10)+(G%10); cout<< p; return 0; } ``` ### 011 ```cpp= #include <iostream> using namespace std; int main() { int s; cin>> s; if(s>=60){ cout<< "PASS"; }else{ cout<< "FAIL"; } } ``` ### 012 ```cpp= #include <iostream> using namespace std; int main() { int x; cin >> x; if (x%2==0){ //% and / cout<<"EVEN"; }else{ cout<<"ODD"; } return 0; } ``` ### 013 ```cpp= #include <iostream> using namespace std; int main() { int a; cin >> a; if ( a>=75&a<=90 ){ cout<< "YES"; }else{ cout<<"NO"; } return 0; } ``` ### 014 ```cpp= #include <iostream> using namespace std; int main() { int a; int b; int c; cin>> a; cin>> b; cin>> c; if(a<=b&&a<=c){ cout<<a; } else if(b<=a&&b<=c){ cout<<b; } else if(c<=a&&c<=b){ cout<<c; } return 0; } ``` ### 015 ```cpp= #include <iostream> using namespace std; int main() { int a; int b; cin >>a>>b; if(a>b){ cout<<a<<">"<<b; } else if(a<b){ cout<<a<<"<"<<b; } else if(a=b){ cout<<a<<"="<<b; } return 0; } ``` ### 016 ```cpp= #include <iostream> using namespace std; int main() { int a; cin>> a; if(a%4!=0){ cout<<"NO"; } else if(a%4==0&&a%100!=0){ cout<<"YES"; } else if(a%100==0&&a%400!=0){ cout<<"NO"; } else if(a%400==0){ cout<<"YES"; } } ``` ### 017 ```cpp= #include <iostream> using namespace std; int main() { int a; cin >> a; if(a>=90&&a<=100){ cout<<"A"; } else if(a>=80&&a<90){ cout<<"B"; } else if(a>=70&&a<80){ cout<<"C"; } else if(a>=60&&a<70){ cout<<"D"; } else{ cout<<"E"; } } ``` ### 018 ```cpp= #include <iostream> using namespace std; int main() { int H; int M; int t; cin >> H>>M; t=H*60+M; if(t<=1000 && t>=860){ cout<<"YES"; }else { cout<<"NO"; } return 0; } ``` ### 019 ```cpp= #include <iostream> using namespace std; int main() { int a; int b; cin>>a>>b; if(b==2||b==5||b==8){ cout<<"200"; } else if(a==1||a==3||a==5||a==7||a==9){ cout<< "100"; } else if(a==b){ cout<< "50"; } else { cout<<"0"; } return 0 ; } ``` ### 020 ```cpp= #include <iostream> using namespace std; int main() { int a; int b; int c; c=0; cin>>a>>b; if(b==2||b==5||b==8) c=c+200; if(a==1||a==3||a==5||a==7||a==9) c=c+100; if(a==b) c=c+50; else c=c+0; cout << c; return 0 ; } ``` ### 021 ```cpp= #include <iostream> using namespace std ; int main() { int a; cin >>a; while (a%2==0){ a=a/2; } cout<< a; } ``` ### 022 ```cpp= #include <iostream> using namespace std; int main() { int n,m,x; cin>> n>> m; x=0; while( n<=m ){ n=n*3; x++; } cout<<x; return 0; } ``` ### 023 ```cpp= #include <iostream> using namespace std; int main() { int n,m; cin>>n; m=0; while(n>1){ if(n%2==1){ n=3*n+1; m++; } else { n=n/2; m++; } } cout<<m+1; return 0; } ``` 這題比較難,需要思考到 while if else 跟迴圈的++關系 ### 024 ```cpp= #include <iostream> using namespace std; int main() { int n; int s=0; int a; cin >> n; while(n%10!=0){ s=s+n%10; n=n/10; if(n%10==0){ //這邊要記得避開0 s=s+0; n=n/10; } } cout<< s; return 0; } ``` ## TOI ### 三月考試-Lucky7 ![](https://i.imgur.com/e9lq9u1.png) ```cpp= #include <iostream> using namespace std ; int main() { int n[9],m,a,b,c=0,d; for(int i=0;i<=9;i++){ cin>> n[i]; if(n[i]==0){ break; } if(i==0){ c=n[i]; continue; } a=n[i]; if(a%7==0 && c%7==0){ if(a%70>c%70){ c=a; }else{ //c=c; } } if(a%7==0 && c%7!=0){ a>c; c=a; } if(a%7!=0 && c%7==0){ a<c; //c=c; } if(a%7!=0 && c%7!=0){ if(a%77 > c%77){ // c=c; }else{ c=a; } } } cout<<c; } ``` 本題注意 1)在這題學到continue跟break用法 2)在if-else要注意,而且我常常不懂自己打的,乾脆用最古老方法,一個條件一個條件來(其實這樣不會打很多東西) ### 三月考試-蟲蟲危機 ![](https://i.imgur.com/v3E0YEw.jpg) ```cpp= #include <iostream> using namespace std ; int main() { int M,N,a=0,b=0; cin>>M>>N; int m[M],n[N]; for(int i=0;i<M;i++){ cin>>m[i]; a=a+m[i]; } for(int p=0;p<N;p++){ cin>>n[p]; b=b+n[p]; } if(M>N & a>b){ cout<<"Yes"; }else{ cout<<"No"; } return 0 ; } ``` spoiler 本題注意 設陣列的位置要注意先後順序! ex: //現在要求一個陣列n[N] 要先cin>>N; 在int n[N] ### 2021.01舉旗遊戲 (Flag) 重要!!雙層迴圈 !大重點 * int a[3] int a[3][2] sort(a[0],a[0]+2)雙層迴圈的排列 * 迴圈中想要做一個大方陣 ```cpp= #include <bits/stdc++.h> using namespace std; #define N 105 int s[N][N]={{0}}; //若是想要單層迴圈 int s[N]={0}; ``` 在這題還用到"布林" bool 啊,簡單來說就是1跟0的對錯 ```cpp= #include <bits/stdc++.h> using namespace std; #define N 105 int s[N][N]={{0}}; int main() { int r,c; cin >> r >> c; for(int i= 1;i<=r;i++){ for(int j=1;j<=c;j++){ cin >> s[i][j]; } } int apple=0; for(int i= 1;i<=r;i++){ for(int j=1;j<=c;j++){ bool g=false; //我找到for之中沒錯的數字變成true,錯的則延續16行印出flase for(int x=i-1;x<=i+1;x++){ //我限制他找9宮格的外圍 //int(從)...到... for(int y=j-1;y<=j+1;y++){ if(x==i & y==j || s[x][y]==0){ //找到依樣或是0都continue continue; }else if(s[i][j]==s[x][y]){ //否則跳出來 g=true; break; } } } if(!g){ apple=apple+1; } } } cout<<apple; } ``` ## APCS ### 2020-10月考試 第一題 [f313: 2. 人口遷移](https:/https://zerojudge.tw/ShowProblem?problemid=f313/) 尚未全部修正的 * 在620到629是要用4個if才會是連續判斷 * 若是用if-elseif只有再**"不滿足第一個判斷"才會往下執行否則"其中一個對,其他就不會執行"** (襪賽!如果謝哥哥沒說我會一直錯下去餒) * 還要注意!有邊界的題目要注意會不會超過或是小於邊界 ```cpp= #include <bits/stdc++.h> using namespace std; #define N 100 int s[N][N]; int main(){ // 先都指定-1 for(int i = 0; i < N; i++){ for(int j = 0; j < N; j++){ s[i][j] = -1; } } // debug // for(int i = 0; i < N; i++){ // for(int j = 0; j < N; j++){ // cout << s[i][j] << " "; // } // cout << endl; // } int r,c,k,m; //姊!小心這邊不要少輸入東西 cin>>r>>c>>k>>m; for(int i=1;i<=r;i++) { //because you already int s[N][N] becarefully!! for(int j=1;j<=c;j++) { cin>>s[i][j]; //remember what is you int! } } for(int z=0;z<m;z++) { //m天之後的結果 //int P=0; //記錄某格移出的人數 //int Q=0; //上下左右有多少是"城市" int v[r+2][c+2]; // 初始化所有元素為0 for(int i=0;i<=r+1;i++) { for(int j=0;j<=c+1;j++) { v[i][j] = 0; } } for(int i=1;i<=r;i++) { for(int j=1;j<=c;j++) { int P=0; int Q=0; P=(s[i][j]/k); if(s[i-1][j]!=-1) //不需要i>=2因為牆壁事0跟r+1又i不會跑到0去,所以不需要i>=2 { v[i-1][j]=P+v[i-1][j]; Q=Q+1; } if(s[i+1][j]!=-1) { v[i+1][j]=P+v[i+1][j]; Q=Q+1; } if(s[i][j-1]!=-1) { v[i][j-1]=P+v[i][j-1]; Q=Q+1; } if(s[i][j+1]!=-1) { v[i][j+1]=P+v[i][j+1]; Q=Q+1; } //用原本有都少人減掉移出去多少城市*多少人 v[i][j]=v[i][j]-(P*Q); //最後原本城市的人剩下多少 } } for(int i=1;i<=r;i++) { for(int j=1;j<=c;j++) { s[i][j] = s[i][j] + v[i][j]; } } } int l=0,K=10000; for(int i=1;i<=r;i++) { for(int j=1;j<=c;j++) { if(s[i][j]>l) { //找最大值 l=s[i][j]; } if(s[i][j]<K && s[i][j]!=-1) { //找最小值(還要排除-1喔!) K=s[i][j]; } } } cout<<K<<endl; cout<<l<<endl; } //這題跟舉旗很類似,but在後面迴圈的地方比較複雜,阿很容易錯小錯餒,請小心 ```