-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmonhavva.cpp
50 lines (41 loc) · 845 Bytes
/
cmonhavva.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
* Problem: C'mon Havva, just let me in..
* URL: https://algoleague.com/contest/problem-of-the-week/problem/cmon-havva-just-let-me-in/detail
*/
#include <bits/stdc++.h>
int main()
{
std::ios_base::sync_with_stdio(false);
std::cin.tie(0);
int n;
std::cin >> n;
char str[n];
std::cin >> str;
int count = 0;
int l = 0;
int r = 0;
for (int i = 1; i < n; i++)
{
l = i - 1;
r = i;
while (l >= 0 && r < n && str[l] == str[r])
{
count++;
l--;
r++;
}
}
for (int i = 1; i < n; i++)
{
l = i - 1;
r = i + 1;
while (l >= 0 && r < n && str[l] == str[r])
{
count++;
l--;
r++;
}
}
std::cout << count << std::endl;
return 0;
}