Skip to content

Commit 65056d6

Browse files
committed
Added 735A -Ostap and Grasshopper.cpp
1 parent b9a139d commit 65056d6

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

735A - Ostap and Grasshopper.cpp

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
// Code Written By: Vikash Patel
5+
6+
int main()
7+
{
8+
int n,k;
9+
cin>>n>>k;
10+
string s;
11+
cin>>s;
12+
int g,t;
13+
int c1=0,c2=0;
14+
for(int i=0;i<n;i++)
15+
{
16+
if(s[i]=='G')
17+
{
18+
g=i;
19+
c1++;
20+
}
21+
if(s[i]=='T')
22+
{
23+
t=i;
24+
c2++;
25+
}
26+
if(c1==1 && c2==1)
27+
{
28+
break;
29+
}
30+
}
31+
int x=0,y=0;
32+
if(g<t)
33+
{
34+
for (int i=g; i<=t; i+=k)
35+
{
36+
if (s[i] == '#')
37+
{
38+
y = 1;
39+
cout << "NO" << endl;
40+
break;
41+
}
42+
else if (s[i] == 'T')
43+
{
44+
y = 1;
45+
cout << "YES" << endl;
46+
break;
47+
}
48+
else if (s[i] != 'T')
49+
x = 0;
50+
}
51+
if (x == 0 && y == 0)
52+
cout << "NO" << endl;
53+
}
54+
else
55+
{
56+
for (int i=t; i<=g; i+=k)
57+
{
58+
if (s[i] == '#')
59+
{
60+
y = 1;
61+
cout << "NO" << endl;
62+
break;
63+
}
64+
else if (s[i] == 'G')
65+
{
66+
y = 1;
67+
cout << "YES" << endl;
68+
break;
69+
}
70+
else if (s[i] != 'G')
71+
x = 0;
72+
}
73+
74+
if (x == 0 && y == 0)
75+
cout << "NO" << endl;
76+
}
77+
}
78+
79+
80+
81+
82+
83+
84+
85+

0 commit comments

Comments
 (0)