Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. char map[102][102]; //地圖製作
  4. int row,col;
  5. int count,max; //定義總礦數以及最大值
  6. void check(int,int);//檢查礦脈
  7. int ans[100][2];
  8.  
  9. int main(void){
  10. int n=0;
  11. while((row=getchar())!='0'){//判斷是否為零
  12. scanf("%d",&col);
  13. row=row-'0';//將row回復
  14. getchar();//將enter去除
  15. int mount=0;//設定總共幾種礦脈
  16. max=0;
  17. for(int i=0;i<row;i++){
  18. scanf("%s",map[i]);//製作地圖
  19. }
  20. for(int i=0;i<row;i++){
  21. for(int j=0;j<col;j++){
  22. if(map[i][j]=='$'){//如果發現礦
  23. count=0;//礦總數歸零
  24. mount++;//礦脈增加
  25. check(i,j);//檢查是否有連動的礦脈
  26. if(max<count){
  27. max=count;//最大值
  28. }
  29. }
  30. }
  31. }
  32. ans[n][0]=mount;
  33. ans[n][1]=max;
  34. n++;
  35. getchar();//去除enter
  36. for(int i=0;i<row;i++){
  37. for(int j=0;j<col+1;j++){
  38. map[i][j]=' ';//清除map
  39. }
  40. }
  41. }
  42. for(int i=0;i<n;i++){
  43. printf("(%d,%d)\n",ans[i][0],ans[i][1]);
  44. }
  45. return 0;
  46. }
  47. void check(int norow,int nocol){
  48. map[norow][nocol]='#';//為避免重複計算,直接將他去除
  49. count++;//礦數+1;
  50. if(map[norow+1][nocol]=='$'){//右
  51. check(norow+1,nocol);
  52. }
  53. if(map[norow][nocol+1]=='$'){//下
  54. check(norow,nocol+1);
  55. }
  56. if(map[norow-1][nocol]=='$'){//左
  57. check(norow-1,nocol);
  58. }
  59. if(map[norow][nocol-1]=='$'){//上
  60. check(norow,nocol-1);
  61. }
  62. if(map[norow+1][nocol+1]=='$'){//右下
  63. check(norow+1,nocol+1);
  64. }
  65. if(map[norow+1][nocol-1]=='$'){//右上
  66. check(norow+1,nocol-1);
  67. }
  68. if(map[norow-1][nocol-1]=='$'){//左下
  69. check(norow-1,nocol-1);
  70. }
  71. if(map[norow-1][nocol+1]=='$'){//左上
  72. check(norow-1,nocol+1);
  73. }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement