-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy path873B.cpp
More file actions
47 lines (42 loc) · 702 Bytes
/
873B.cpp
File metadata and controls
47 lines (42 loc) · 702 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
45
46
47
#include<iostream>
#include<string>
using namespace std;
int fun(string s, int n){
int a = 0, b = 0;
if(n==1){
cout<<-1<<" ";
cout<<-1<<endl;
return 0;
}
for(int r = n-1; r > 0; r--){
for(int l = 0; l < r; l++){
for(int i = l; i <= r; i++){
if(s[i] == 'a'){
a++;
}
else{
b++;
}
}
if(a == b){
cout<<(l+1)<<" ";
cout<<(r+1)<<endl;
return 0;
}
a = 0; b = 0;
}
}
cout<<-1<<" ";
cout<<-1<<endl;
return 0;
}
int main(){
int t, n;
cin>>t;
string s;
for(int j = 0; j < t; j++){
cin>>n;
cin>>s;
fun(s, n);
}
}