[C++] NCYU 回家功課09

請不要直接抄寫程式碼! 也請不要直接跳到程式碼部分,除非你已經寫好了,想要參考別人的寫法! 回家功課09 先觀察圖形: 輸入 3 就會有 3 行 3 列、輸入 5 就會有 5 行 5 列,所以輸入 n 就會有 n 行 n 列 第一列的 o 在最中間、第 n 列的 o 從中間往兩邊增加,而且最中間那列全為 o (最中間怎麽用 n 表示呢?) 不是 x 的地方就是 o o 的變化很像 擴散 ,每多一行 o 就往兩邊擴散一個,經過中間那列之後,就開始 縮減 要注意是小寫 xo !!!! 程式碼大概如下: #include <iostream> using namespace std; int main() { int n; cin>>n; int center = n/2+1; int offset = 0; for(int row=1;row<=n;row++){ for(int col=1;col<=n;col++){ if ( col>center+offset || col<center-offset ) cout<<"x"; else cout<<"o"; } if ( row<center ) offset++; else offset--; cout<<endl; } } 1 2 3 4 5 6 7 1 2 3 4 5 6 7 1 2 3 4 5 6 7 1 2 3 4 5 6 7 1 2 3 4 5 6 7 1 2 3 4 5 6 7 1 2 3 4 5 6 7 x x x o x x x x x o o o x x x o o o o o x o o o o o o o x o o o o o x x x o o o x x x x x o x x x 如果有任何問題,歡迎私訊跟我討論喔!

October 30, 2020 · 1 min · CPP

[C++] NCYU TA課練習02

請不要直接抄寫程式碼! 也請不要直接跳到程式碼部分,除非你已經寫好了,想要參考別人的寫法! #include <iostream> using namespace std; int main() { string number; cin>>number; int length = number.size(); for(int i=length-1;i>=0;i--){ if ( number[i]-48!=0 ){ length = i; break; } } for(int i=length;i>=0;i--) cout<<number[i]; cout<<endl; } 如果有任何問題,歡迎私訊跟我討論喔!

October 30, 2020 · 1 min · CPP

[C++] NCYU TA課練習01

請不要直接抄寫程式碼! 也請不要直接跳到程式碼部分,除非你已經寫好了,想要參考別人的寫法! #include <iostream> #include <algorithm> using namespace std; int main() { int t; cin>>t; while(t>0){ int number[3]; cin>>number[0]>>number[1]>>number[2]; sort(number,number+3); reverse(number,number+3); cout<<number[0]<<" "<<number[1]<<" "<<number[2]<<endl; t--; } } 如果有任何問題,歡迎私訊跟我討論喔!

October 30, 2020 · 1 min · CPP

[C++] NCYU 回家功課08

請不要直接抄寫程式碼! 也請不要直接跳到程式碼部分,除非你已經寫好了,想要參考別人的寫法! #include <iostream> #include <sstream> using namespace std; int main() { int hour,minute,second; char symbol; int priorTime,currentTime; string time; stringstream prior,current; cin>>time; prior<<time; prior>>hour>>symbol>>minute>>symbol>>second; priorTime = hour*3600 + minute*60 + second; cin>>time; current<<time; current>>hour>>symbol>>minute>>symbol>>second; currentTime = hour*3600 + minute*60 + second; int delta = (currentTime - priorTime); delta = ( delta/3600 > 0 ) ? ( delta%3600 > 0 ) ? delta/3600 : delta/3600-1 : 0 ; cout<<delta*20<<endl; } 如果有任何問題,歡迎私訊跟我討論喔!

October 30, 2020 · 1 min · CPP

[C++] NCYU 回家功課07

請不要直接抄寫程式碼! 也請不要直接跳到程式碼部分,除非你已經寫好了,想要參考別人的寫法! #include <iostream> using namespace std; int main() { string number; cin>>number; // firstLine for(int i=0;i<3;i++){ switch(number[i]-48){ case 1: cout<<" *"; break; case 4: cout<<"* *"; break; default: cout<<"*****"; break; } if(i!=2) cout<<" "; } cout<<endl; // secondLine for(int i=0;i<3;i++){ switch(number[i]-48){ case 1: case 2: case 3: case 7: cout<<" *"; break; case 5: case 6: cout<<"* "; break; default: cout<<"* *"; break; } if(i!=2) cout<<" "; } cout<<endl; // thirdLine for(int i=0;i<3;i++){ switch(number[i]-48){ case 0: cout<<"* *"; break; case 1: case 7: cout<<" *"; break; default: cout<<"*****"; break; } if(i!...

October 30, 2020 · 1 min · CPP