# 二維陣列 ##### tags: `c++` 二維陣列簡而言之就是一個二維平面上的表,而每一個座標代表一個數值。  在這裡我們稱(1,1)為左上角數值 ```cpp= int x[10][10]; for(int i = 1 ; i <= 2 ; i++) // 這裡輸入4 5 6 7 8 0 { for(int j = 1 ; j <= 3 ; j++) { cin >> x[i][j]; } } cout << x[1][1] << '\n'; // 輸出結果為4 ``` 所以簡單來說二維就類似於一個表格,但是通常有其他的用法,如果以後走競賽組的話會教,基本上第一次留社考學到這裡就可以了。 那這裡舉例toj114 就用剛剛上面雙層迴圈輸入一次數值 然後每一次都根據他的條件判斷是否相等 前幾屆學長的AC code ```cpp= #include<iostream> using namespace std; int main(){ int arr[5][6]; for(int i=0 ; i<5 ; i++){ for(int j=0 ; j<6 ; j++){ cin>>arr[i][j]; } } bool find_ans=false; // row for(int i=0,cnt=1 ; i<5 ; i++,cnt=1){ for(int j=1 ; j<6 && !find_ans ; j++){ if(arr[i][j] == arr[i][j-1]) cnt++; else cnt=1; if(cnt==3) find_ans=true; } } // col for(int j=0,cnt=1 ; j<6 ; j++,cnt=1){ for(int i=1 ; i<5 && !find_ans ; i++){ if(arr[i][j] == arr[i-1][j]) cnt++; else cnt=1; if(cnt==3) find_ans=true; } } if(find_ans) cout<<"Yes\n"; else cout<<"No\n"; return 0; } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up