C.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int N = 100;
  4. char a[N+2][N+2];
  5. int n,m;
  6. int dir[4][2] = {1,0,-1,0,0,1,0,-1};
  7. void dfs(int x,int y){
  8. a[x][y] = '#';
  9. for(int k = 0; k <= 3;k ++){
  10. int tx = x + dir[k][0];
  11. int ty = y + dir[k][1];
  12. if(tx >= n+2 || ty >= m+2 || tx < 0 || ty < 0 || a[tx][ty] =='#'){
  13. continue;
  14. }
  15. dfs(tx,ty);
  16. }
  17. }
  18. int main(){
  19. int T;
  20. cin >> T;
  21. int t=0;
  22. while (T--){
  23. cin >> n >> m;
  24. for(int i = 0; i <= n+1; i ++){
  25. for(int j = 0; j <= m+1; j++){
  26. a[i][j]='.';
  27. }
  28. }
  29. for(int i = 1; i <= n; i++){
  30. scanf("%s",a[i]+1);
  31. }
  32. dfs(0,0);
  33. int sum = 0;
  34. for(int i = 0; i <= n+1; i++){
  35. for(int j = 0; j <= m+1; j++){
  36. if(a[i][j]=='#'){
  37. sum++;
  38. }
  39. }
  40. }
  41. cout << "Case "<<++t<<": ";
  42. if(sum == (n+2)*(m+2)){
  43. cout << "H"<<endl;
  44. }
  45. else{
  46. cout << "A"<<endl;
  47. }
  48. }
  49. }