-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathapr2.cpp
More file actions
44 lines (42 loc) · 846 Bytes
/
apr2.cpp
File metadata and controls
44 lines (42 loc) · 846 Bytes
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
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
int j , t;
cin>>t;
for(j=0 ; j<t ;j++)
{
char ch ;
int n ,i;
cin>>n;
char a[n];
for(i=0 ; i<n ; i++)
{
cin>>a[i];
}
cin>>ch;
int m=0,q=0;
for(i=0 ; i<n ; i++)
{
if(a[i]!=ch)
m++;
else
q++;
}
if((ch==a[0]||ch==a[n-1])&&q==1)
{
cout<<n<<endl;
}
else if(q==1)
{
int a = n*(n+1)/2 -((n-3)*(n-2)/2)-m;
cout<<a<<endl;
}
else
{
int b = n*(n+1)/2 -((n-3)*(n-2)/2)-m + (n-3)*q;
cout<<b<<endl;
}
}
}