Codeforces Beta Round #6 (Div. 2 Only) 6B - President's Office Solution

 




  Problem Link:  https://codeforces.com/contest/6/problem/B

Solution in C++:

  1. /// La ilaha illellahu muhammadur rasulullah
  2. ///******Bismillahir-Rahmanir-Rahim******///
  3. /// Abul Hasnat Tonmoy
  4. /// Department of CSE,23rd batch
  5. /// Islamic University,Bangladesh
  6. ///**********ALLAH IS ALMIGHTY************///
  7. #include <bits/stdc++.h>
  8. using namespace std;
  9. int n, m, ans;
  10. char x, a[110][110];
  11. int main() {
  12. cin >> n >> m >> x;
  13. set < char > st;
  14. memset(a, '0', sizeof(a));
  15. for (int i = 1; i <= n; i++)
  16. for (int j = 1; j <= m; j++) cin >> a[i][j];
  17. for (int i = 1; i <= n; i++)
  18. for (int j = 1; j <= m; j++) {
  19. if (a[i][j] == x) {
  20. if (a[i - 1][j] != '.' && a[i - 1][j] != '0') st.insert(a[i - 1][j]);
  21. if (a[i + 1][j] != '.' && a[i + 1][j] != '0') st.insert(a[i + 1][j]);
  22. if (a[i][j - 1] != '.' && a[i][j - 1] != '0') st.insert(a[i][j - 1]);
  23. if (a[i][j + 1] != '.' && a[i][j + 1] != '0') st.insert(a[i][j + 1]);
  24. }
  25. }
  26. int cn = 0;
  27. for (auto it: st) {
  28. if (it == x) cn++;
  29. }
  30. cout << st.size() - cn << endl;
  31. return 0;
  32. }

No comments

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h &g...

Powered by Blogger.