Skip to content

Commit dfc263d

Browse files
authored
Merge pull request #474 from himanshu007-creator/patch-2
Create covid and cousin solution.cpp
2 parents 469f3aa + 3715b93 commit dfc263d

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#include<iostream>
2+
using namespace std;
3+
int main()
4+
{
5+
int t,s,d,f,b,m,k;
6+
cin>>k;
7+
for(int i=0;i<k;i++)
8+
{
9+
cin>>t;
10+
cin>>s;
11+
cin>>d;
12+
cin>>f;
13+
cin>>b;
14+
m = 0;
15+
while((s!=d) && (s<=t) && (d<=t))
16+
{
17+
if((s<d) && (f==0))
18+
{
19+
break;
20+
}
21+
while((s<d) && (f!=0))
22+
{
23+
s+=f;
24+
m+=1;
25+
}
26+
if((s>d) && (b==0))
27+
{
28+
break;
29+
}
30+
while((s>d) && (b!=0))
31+
{
32+
s-=b;
33+
m+=1;
34+
}
35+
if(s==d)
36+
{
37+
cout<<m;
38+
}
39+
else
40+
{
41+
cout<<"Not Reachable";
42+
}
43+
}
44+
}
45+
return 0;
46+
}
47+

0 commit comments

Comments
 (0)