标签:style blog http color os io for art
题目链接:http://acm.hnu.cn/online/?action=problem&type=show&id=12868&courseid=272
解题报告:输入n*m的地图,+表示土地,-表示水,要你求这个海岛的海岸线有多长,扫一遍就可以了。
1 #include<cstdio> 2 const int maxn = 2000; 3 char map[maxn][maxn]; 4 int _x[4] = {-1,0,1,0}; 5 int _y[4] = {0,1,0,-1}; 6 7 int main() 8 { 9 int n,m; 10 while(scanf("%d%d",&n,&m)!=EOF) 11 { 12 for(int i = 0;i < n;++i) 13 scanf("%s",map[i]); 14 int tot = 0; 15 for(int i = 0;i < n;++i) 16 for(int j = 0;j < m;++j) 17 if(map[i][j] == ‘+‘) 18 { 19 int flag = 0; 20 for(int k = 0;k < 4;++k) 21 { 22 int xx = i + _x[k]; 23 int yy = j + _y[k]; 24 if(xx >= 0 && xx < n && yy >= 0 && yy < m) 25 if(map[xx][yy] == ‘-‘ || map[xx][yy] == ‘?‘) 26 { 27 flag = 1; 28 break; 29 } 30 } 31 if(flag == 1) tot++; 32 } 33 printf("%d\n",tot); 34 } 35 return 0; 36 }
HNU 12868 Island (简单题),布布扣,bubuko.com
标签:style blog http color os io for art
原文地址:http://www.cnblogs.com/xiaxiaosheng/p/3898074.html