Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- char map[102][102]; //地圖製作
- int row,col;
- int count,max; //定義總礦數以及最大值
- void check(int,int);//檢查礦脈
- int ans[100][2];
- int main(void){
- int n=0;
- while((row=getchar())!='0'){//判斷是否為零
- scanf("%d",&col);
- row=row-'0';//將row回復
- getchar();//將enter去除
- int mount=0;//設定總共幾種礦脈
- max=0;
- for(int i=0;i<row;i++){
- scanf("%s",map[i]);//製作地圖
- }
- for(int i=0;i<row;i++){
- for(int j=0;j<col;j++){
- if(map[i][j]=='$'){//如果發現礦
- count=0;//礦總數歸零
- mount++;//礦脈增加
- check(i,j);//檢查是否有連動的礦脈
- if(max<count){
- max=count;//最大值
- }
- }
- }
- }
- ans[n][0]=mount;
- ans[n][1]=max;
- n++;
- getchar();//去除enter
- for(int i=0;i<row;i++){
- for(int j=0;j<col+1;j++){
- map[i][j]=' ';//清除map
- }
- }
- }
- for(int i=0;i<n;i++){
- printf("(%d,%d)\n",ans[i][0],ans[i][1]);
- }
- return 0;
- }
- void check(int norow,int nocol){
- map[norow][nocol]='#';//為避免重複計算,直接將他去除
- count++;//礦數+1;
- if(map[norow+1][nocol]=='$'){//右
- check(norow+1,nocol);
- }
- if(map[norow][nocol+1]=='$'){//下
- check(norow,nocol+1);
- }
- if(map[norow-1][nocol]=='$'){//左
- check(norow-1,nocol);
- }
- if(map[norow][nocol-1]=='$'){//上
- check(norow,nocol-1);
- }
- if(map[norow+1][nocol+1]=='$'){//右下
- check(norow+1,nocol+1);
- }
- if(map[norow+1][nocol-1]=='$'){//右上
- check(norow+1,nocol-1);
- }
- if(map[norow-1][nocol-1]=='$'){//左下
- check(norow-1,nocol-1);
- }
- if(map[norow-1][nocol+1]=='$'){//左上
- check(norow-1,nocol+1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement