NSTEPS - Number Steps Editorial SPOJ - UCS - Unleash-Coding-Skills

Thursday, 3 May 2018

NSTEPS - Number Steps Editorial SPOJ - UCS

The link for the problem  NSTEPS - Number Steps:

http://www.spoj.com/problems/NSTEPS/

Initially, you need to check whether the Y coordinate is even or odd based on that further cases are validated and printed as shown in the solution.

The CPP solution for NSTEPS - Number Steps:

#include <iostream>
using namespace std;

int main() {
long long int i,j,k,t,x,y,ans;
cin>>t;
for(i=0;i<t;i++)
{
      cin>>x>>y;
      if(y%2==0)
      {
      ans=y*2;
      if(x==y)
      {
            cout<<ans<<endl;
      }
      else if(x==y+2)
      {
            cout<<ans+2<<endl;
      }
      else
      cout<<"No Number"<<endl;
      }
      else 
      {
      k=y-1;
      ans=k*2;
            if(x==k+1)
            {
                  cout<<ans+1<<endl;
            }
            else if(x==k+3)
            {
                  cout<<ans+3<<endl;
            }
            else
            cout<<"No Number"<<endl;
      }
      
}
return 0;
}

Happy Coding.......

No comments:

Post a comment