- #include <iostream>
- #include <cstdlib>
- using namespace std;
- int main(){
- int b , c;
- int x = 0;
- string a;
- while(cin >> b >> c){
- int d[b][c];
-
- for(int i = 0; i < b; i++){
- cin >> a;
- for(int j = 0; j < c; j++){
- d[i][j] = ((int)a[j])-48;
- }
- }
-
- for(int i = 0; i < b; i++){
- for(int j = 0; j < c; j++){
- if(d[i][j] == 1){
- if(i+1 == b || d[i+1][j] == 0){
- x++;
- }
- if(j+1 == c || d[i][j+1] == 0){
- x++;
- }
- if(i-1 < 0 || d[i-1][j] == 0){
- x++;
- }
- if(j-1 < 0 || d[i][j-1] == 0){
- x++;
- }
- }
- }
- }
-
- cout << x << endl;
- x=0;
-
- }
- return 0;
- }
複製代碼 ㄏㄏ我好厲害喔 |