forked from Saiyamjain-100/coder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathA_Balanced_Substring.cpp
85 lines (80 loc) · 1.63 KB
/
A_Balanced_Substring.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
78
79
80
81
82
83
84
85
#include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
void hehe() {
#ifndef RTE
if (fopen("input.txt", "r")) {
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
}
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
int modularExponentiation(long long int x,long long int n,long long int M)
{
long long int result=1;
while(n>0)
{
if(n % 2 ==1)
result=(result * x)%M;
x=(x*x)%M;
n=n/2;
}
return result;
}
long long power(long long a, long long b) {
if (b == 0)
return 1;
long long res = power(a, b / 2);
if (b % 2)
return res * res * a;
else
return res * res;
}
int fact(int n) {
if (n == 0 || n == 1)
return 1;
else
return n * fact(n - 1);
}
void solve(){
ll n,i,l,r;cin>>n;
string s;cin>>s;
if(n==1){
l=-1;
r=-1;
}
else{
for(i=0;i<n;i++){
if(s[i]=='a'){
if(s[i+1]=='b'){
l=i+1;
r=i+2;
break;
}
}
else if(s[i]=='b'){
if(s[i+1]=='a'){
l=i+1;
r=i+2;
break;
}
}
else
{
l=-1;
r=-1;
}
}
}
cout<<l<<" "<<r<<endl;
}
int main(){
hehe();
int t;cin>>t;
while(t--)
solve();
}