-
Notifications
You must be signed in to change notification settings - Fork 3
/
solution.cpp
77 lines (58 loc) · 1.14 KB
/
solution.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
//data types
typedef long long ll;
typedef long double lld;
//constants
const lld pi= 3.141592653589793238;
const ll INF= LONG_LONG_MAX;
const ll mod=1e9+7;
//Macros
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define newl cout<<"\n";
//int c = 1;
//solution area
void solve(){
int n;
char c;
string s;
cin>>n>>c>>s;
vector<int>color;
vector<int> green;
if(c == 'g'){
cout<<0<<endl;
return;
}
for(int i = 0; i < n; i++){
if(s[i] == c) color.pb(i);
if(s[i] == 'g')green.pb(i);
}
int max = 0;
if(color.end()>green.end()){
max = green.begin()+n-color.end();
}
for(int i = 0; i < color.size(); i++){
for(int j = 0; j < green.size(); j++){
if(color[i] < green[j]){
int val = green[i] - color[i];
if(val > max) max = val;
}
}
}
cout<<max<<endl;
}
//main function area
int main(){
//faster input and output
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin>>t;
while (t--){
solve();
}
}