forked from legendary-acp/Basic_programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRight left.cpp
More file actions
49 lines (49 loc) · 879 Bytes
/
Right left.cpp
File metadata and controls
49 lines (49 loc) · 879 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
48
49
#include<iostream>
using namespace std;
int main()
{
long int n,q;
cin>>n>>q;
long int a[n],i=0;
while(i<n)
{
cin>>a[i];
i++;
}
while(q--)
{
long int x,y,flag=0,count=0,j;
char d;
cin>>x>>y>>d;
i=0;j=a[x];
while(i<n)
{
if(y==a[i])
flag=1;
if(flag==1&&j!=y)
{
if(d=='R')
while(j!=y)
{
x=(x+1)%n;
j=a[x];
count++;
}
else
while(j!=y)
{
x=(x-1+n)%n;
j=a[x];
count++;
}
i=n;
}
i++;
}
if(flag==1)
cout<<count<<endl;
else
cout<<"-1\n";
}
return 0;
}