Codeforces Beta Round #6 (Div. 2 Only) 6B - President's Office Solution
Problem Link: https://codeforces.com/contest/6/problem/B
Solution in C++:
- /// La ilaha illellahu muhammadur rasulullah
- ///******Bismillahir-Rahmanir-Rahim******///
- /// Abul Hasnat Tonmoy
- /// Department of CSE,23rd batch
- /// Islamic University,Bangladesh
- ///**********ALLAH IS ALMIGHTY************///
- #include <bits/stdc++.h>
- using namespace std;
- int n, m, ans;
- char x, a[110][110];
- int main() {
- cin >> n >> m >> x;
- set < char > st;
- memset(a, '0', sizeof(a));
- for (int i = 1; i <= n; i++)
- for (int j = 1; j <= m; j++) cin >> a[i][j];
- for (int i = 1; i <= n; i++)
- for (int j = 1; j <= m; j++) {
- if (a[i][j] == x) {
- if (a[i - 1][j] != '.' && a[i - 1][j] != '0') st.insert(a[i - 1][j]);
- if (a[i + 1][j] != '.' && a[i + 1][j] != '0') st.insert(a[i + 1][j]);
- if (a[i][j - 1] != '.' && a[i][j - 1] != '0') st.insert(a[i][j - 1]);
- if (a[i][j + 1] != '.' && a[i][j + 1] != '0') st.insert(a[i][j + 1]);
- }
- }
- int cn = 0;
- for (auto it: st) {
- if (it == x) cn++;
- }
- cout << st.size() - cn << endl;
- return 0;
- }
No comments