Source Code
#include <iostream>
using namespace std;


int main(){
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
	
	int n, ans = 0;
	string x;
	cin >> n;
	cin >> x;
	int l = x[0];
	int m = n-1;
	int i = 0, k = x[n-1];
	for (int f = 0; f < n; f++)
	{
		if (x[i] == l && x[m] == k)
		{
			++ans;
			i++;
			continue;
		}
		if (x[i] == l && x[m] == k)
		{
			++ans;
			m--;
			continue;
		}
	}
	
	cout << ans;

	return 0;
}

Copy
Pop Pop microwave6
GNU G++17
0 ms
504 KB
Wrong Answer
Test Case #1
0 ms
228 KB
Accepted
Input
5
11100
Output
3
Judge Output
3
Checker Message
"3"
Test Case #2
0 ms
504 KB
Wrong Answer
Input
10
1100010011
Output
2
Judge Output
9
Checker Message
1st words differ - expected: '9', found: '2'