-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path018.Chef_and_his_Students.cpp
36 lines (35 loc) · 1.05 KB
/
018.Chef_and_his_Students.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
//Chef and his Students-codechef(1047)
/*
we need to first reverse the '<' as '>' and vice versa
then if , Ai is not equal to '*'(as they are given only 3 symbols i.e., '*', '<', '>' so if it is not equal to '*', automatically it is equal to one of the symbols '<' or '>'),
we check if it is equal to '>' and A[i+1] is equal to '<', then we increment count by 1, and we skip one iteration by incrementing i by 1(as we have already checked for A[i+1] also here.
*/
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while(t--){
string s;
cin >> s;
for(int i=0;i<s.size();i++){
if(s[i]=='<')
{
s[i]='>';
continue;
}
if(s[i]=='>')s[i]='<';
}
// cout<<s<<endl;
int cnt=0;
for(int i=0;i<s.size()-1;i++){
if(s[i]!='*'){
if(s[i]=='>' && s[i+1]=='<'){
cnt++;
i++;
}
}
}
cout<<cnt<<endl;
}
}