fork download
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include <string.h>
  4.  
  5. int main(){
  6.  
  7. int num,x=0,y=0;
  8. char array[105][105];
  9. char str[105];
  10. int i=0,j=0,k=0;
  11. int flag=1, count=1;
  12.  
  13.  
  14. gets(str);
  15. sscanf(str,"%d",&num);
  16.  
  17. while( num ){
  18. for(i=0;i<105;i++)
  19. for(j=0;j<105;j++)
  20. array[i][j] = '1';
  21.  
  22. gets(str);
  23. sscanf(str,"%d %d",&x,&y);
  24. // printf("x = %d, y = %d \n",x,y);
  25.  
  26. i=1;
  27. while( 1 ){
  28. // printf("strlen(str) = %d\n",strlen(str));
  29. if(strlen(str) == 0) break;
  30. gets(str);
  31.  
  32. j=1,k=0;
  33. while(strlen(str) != 0){
  34. array[i][j]=str[k];
  35. k++;
  36. j++;
  37. if(str[k]=='\0') break;
  38. }
  39. i++;
  40. }
  41. /*
  42.   for(i=0;i<10;i++){
  43.   for(j=0;j<10;j++)
  44.   printf("%c",array[i][j]);
  45.   printf("\n");
  46.   }
  47. */
  48. flag=1;
  49. count=0;
  50. if(array[x][y] == '0'){
  51. array[x][y] = '2';
  52. count++;
  53. while(flag == 1){
  54.  
  55. flag = 0;
  56.  
  57. for(i = 0; i < 100; i++)
  58. for(j = 0; j < 100; j++){
  59. if(array[i][j] == '2'){
  60. if(array[i+1][j] == '0'){
  61. array[i+1][j] = '2';
  62. count++;
  63. flag=1;
  64. }
  65. if(array[i-1][j] == '0'){
  66. array[i-1][j] = '2';
  67. count++;
  68. flag=1;
  69. }
  70. if(array[i][j+1] == '0'){
  71. array[i][j+1] = '2';
  72. count++;
  73. flag=1;
  74. }
  75. if(array[i][j-1] == '0'){
  76. array[i][j-1] = '2';
  77. count++;
  78. flag=1;
  79. }
  80. }
  81. }
  82. }
  83. printf("%d\n",count);
  84. }
  85. else printf("%d\n",count);
  86.  
  87. num--;
  88. }
  89.  
  90. system("pause");
  91. return 0;
  92.  
  93. }
  94.  
  95.  
Success #stdin #stdout 0s 2896KB
stdin
Standard input is empty
stdout
Standard output is empty