Advertisement
JouJoy

Untitled

Dec 20th, 2021
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. using namespace std;
  5. pair<int,int> find_center(vector <string> S, int m)
  6. {
  7. pair<int, int> temp;
  8. temp.first = 0;
  9. temp.second = 0;
  10. for (int i = 1; i < S.size()-1; i++)
  11. {
  12. for (int j = 1; j < m - 1; j++)
  13. {
  14. if (S[i - 1][j] == '*' && S[i + 1][j] == '*' && S[i][j + 1]=='*' && S[i][j - 1] == '*')
  15. {
  16. temp.first = i;
  17. temp.second = j;
  18. return temp;
  19. }
  20. }
  21. }
  22. return temp;
  23. }
  24. int main()
  25. {
  26. int h, w;
  27. cin >> h>> w;
  28. vector <string> s;
  29. s.resize(h);
  30.  
  31. int count_pluses = 0;
  32. for (int i = 0; i < h; i++)
  33. {
  34. cin >> s[i];
  35. for (int j = 0; j < w; j++)
  36. {
  37. if (s[i][j] == '*')
  38. {
  39. count_pluses++;
  40. }
  41. }
  42. }
  43. pair<int, int> coord = find_center(s, w);
  44. int count_temp = 0;
  45. if (coord.first == 0 && coord.second == 0)
  46. {
  47. cout << "NO";
  48. return 0;
  49. }
  50. int l, d;
  51. for (int k = 1; k <= 4; k++)
  52. {
  53.  
  54. l = coord.first;
  55. d = coord.second;
  56. while (l < s.size() && l>=0 && d < w&&d>=0&& s[l][d] == '*')
  57. {
  58. count_temp++;
  59. switch (k)
  60. {
  61. case 1:
  62. {
  63.  
  64. l++;
  65. break;
  66. }
  67. case 2:
  68. {
  69. l--;
  70. break;
  71. }
  72. case 3:
  73. {
  74. d++;
  75. break;
  76. }
  77. case 4:
  78. d--;
  79. break;
  80. default:
  81. break;
  82. }
  83. }
  84.  
  85. }
  86. if (count_temp -3 == count_pluses)
  87. cout << "YES" << endl;
  88. else cout << "NO" << endl;
  89.  
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement