<style> html, body, .ui-content { background-color: #333; color: #ddd; } body > .ui-infobar { display: none; } .ui-view-area > .ui-infobar { display: block; } .markdown-body h1{ color: #9CCEF2; } .markdown-body h2, .markdown-body h3{ color: #B1D6CA; } .markdown-body h4, .markdown-body h5, .markdown-body h6 { color: #ddd; } .markdown-body h1, .markdown-body h2 { border-bottom-color: #ffffff69; } .markdown-body h1 .octicon-link, .markdown-body h2 .octicon-link, .markdown-body h3 .octicon-link, .markdown-body h4 .octicon-link, .markdown-body h5 .octicon-link, .markdown-body h6 .octicon-link { color: #fff; } .markdown-body img { background-color: transparent; } .ui-toc-dropdown .nav>.active:focus>a, .ui-toc-dropdown .nav>.active:hover>a, .ui-toc-dropdown .nav>.active>a { color: white; border-left: 2px solid white; } .expand-toggle:hover, .expand-toggle:focus, .back-to-top:hover, .back-to-top:focus, .go-to-bottom:hover, .go-to-bottom:focus { color: white; } .ui-toc-dropdown { background-color: #333; } .ui-toc-label.btn { background-color: #191919; color: white; } .ui-toc-dropdown .nav>li>a:focus, .ui-toc-dropdown .nav>li>a:hover { color: white; border-left: 1px solid white; } .markdown-body blockquote { color: #bcbcbc; } .markdown-body table tr { background-color: #5f5f5f; } .markdown-body table tr:nth-child(2n) { background-color: #4f4f4f; } .markdown-body code, .markdown-body tt { color: #eee; background-color: rgba(230, 230, 230, 0.36); } a, .open-files-container li.selected a { color: #5EB7E0; } </style> ###### tags: `tgirc早修book` # Ch.05 題目練習 ## 一維陣列 <font color="FEA0A0">**題目**</font> 1. [Zerojudge d660: 11764 - Jumping Mario](https://zerojudge.tw/ShowProblem?problemid=d660) 2. [Zerojudge b558: 求數列第 n 項](https://zerojudge.tw/ShowProblem?problemid=b558) 3. [Zerojudge a253: 王老先生的磨菇田](https://zerojudge.tw/ShowProblem?problemid=a253) 4. [Kattis Reduced ID Numbers](https://open.kattis.com/problems/reducedidnumbers) 5. [Zerojudge a240: 第一題:1 / 17 小數第 n 位](https://zerojudge.tw/ShowProblem?problemid=a240) 6. [CSES Missing Number](https://cses.fi/problemset/task/1083) 7. [Kattis Free Food](https://open.kattis.com/problems/freefood) 8. [Kattis Hot Hike](https://open.kattis.com/problems/hothike) :::spoiler <font color="FEA0A0">**題解**</font> 1. [Zerojudge d660: 11764 - Jumping Mario](https://zerojudge.tw/ShowProblem?problemid=d660) ```cpp= #include <iostream> using namespace std; int wall[55]; int main(){ int t; cin>>t; int k=1; //計算第幾個 Case while(t--){ //執行 t 次 int n; cin>>n; for(int i=0;i<n;i++){ cin>>wall[i]; //輸入每個牆壁高度 } int up=0,down=0; for(int i=0;i<n-1;i++){ if(wall[i]<wall[i+1]){ //計算往上跳的次數 up++; } if(wall[i]>wall[i+1]){ //計算往下跳的次數 down++; } } cout<<"Case "<<k<<": "<<up<<' '<<down<<'\n'; k++; //輸出完是第幾個 Case 後,每輪再往上加 1 } return 0; } ``` <!-- 3. [Zerojudge a253: 王老先生的磨菇田](https://zerojudge.tw/ShowProblem?problemid=a253) 4. [Kattis Reduced ID Numbers](https://open.kattis.com/problems/reducedidnumbers) 5. [Zerojudge a240: 第一題:1 / 17 小數第 n 位](https://zerojudge.tw/ShowProblem?problemid=a240) 6. [CSES Missing Number](https://cses.fi/problemset/task/1083) 7. [Kattis Free Food](https://open.kattis.com/problems/freefood) 8. [Kattis Hot Hike](https://open.kattis.com/problems/hothike) --> 2. [Zerojudge b558: 求數列第 n 項](https://zerojudge.tw/ShowProblem?problemid=b558) (待補) ::: ## 二維、多維陣列 <font color="FEA0A0">**題目**</font> 1. [Zerojudge a015: 矩陣的翻轉](https://zerojudge.tw/ShowProblem?problemid=a015) 2. [Toj 114 / 我閉著眼](https://toj.tfcis.org/oj/pro/114/) 3. [Zerojudge d625: 踩地雷真好玩](https://zerojudge.tw/ShowProblem?problemid=d625) 4. [Zerojudge b965: 第 2 題 矩陣轉換](https://zerojudge.tw/ShowProblem?problemid=b965) 5. [UVA Q118 Mutant Flatworld Expolrers ](http://domen111.github.io/UVa-Easy-Viewer/?118) 6. [Kattis This Ain't Your Grandpa's Checkerboard](https://open.kattis.com/problems/thisaintyourgrandpascheckerboard) 7. [Kattis Cudoviste](https://open.kattis.com/problems/cudoviste) :::spoiler <font color="FEA0A0">**題解**</font> 2. [Toj 114 / 我閉著眼](https://toj.tfcis.org/oj/pro/114/) ```cpp= #include <iostream> using namespace std; int ary[8][9]; int main(){ int i,j; for(i=1;i<=5;i++){ for(j=1;j<=6;j++){ cin>>ary[i][j]; } } int k=0; for(i=1;i<=5;i++){ for(j=1;j<=6;j++){ if(ary[i][j] == ary[i][j-1] && ary[i][j] == ary[i][j+1]){ k++; } else if(ary[i][j] == ary[i-1][j] && ary[i][j] == ary[i+1][j]){ k++; } } } if(k!=0) cout<<"Yes\n"; else cout<<"No\n"; return 0; } ``` 7. [Kattis Cudoviste](https://open.kattis.com/problems/cudoviste) ```cpp= #include <bits/stdc++.h> using namespace std; char ary[60][60]; int ans[5]; int main(){ int r,c; cin>>r>>c; int i,j; for(i=1; i<=r; i++){ for(j=1; j<=c; j++){ cin>>ary[i][j]; } } int b[5]={0,1,1,0,0}; int p=0; for(i=1; i<r; i++){ for(j=1; j<c; j++){ for(int k=0;k<4;k++){ if(ary[i+b[k]][j+b[k+1]] == '#'){ p=-1; break; } else if(ary[i+b[k]][j+b[k+1]] == 'X') p++; } if(p>=0) ans[p]++; p=0; } } for(i=0;i<5;i++){ cout<<ans[i]<<"\n"; } return 0; } ``` :::