Showing posts with label Race. Show all posts
Showing posts with label Race. Show all posts

Sunday, June 26, 2022

Race

 Race

Problem Statement
Naruto and Sasuke are on a S- Rank mission. They got bored and thought of competing in a race against each other in a horizontal plane. They decided a common spot "C" at which both of them will try to reach. Whoever reaches first wins the race, both of them run at the same speed.
Given initial positions of Naruto and Sasuke you need to tell which of them will win the race. If Naruto wins print "N" ( without the quotes ), if Sasuke wins print "S" ( without the quotes ).
if both of them reach the common spot at the same time, print "D" (for draw, without the quotes ).


static char Race(int A,int B,int C){
//Enter your code here
if(Math.abs(C-A)==Math.abs(B-C)){
    return 'D';
}
else if(Math.abs(C-A)>Math.abs(B-C)){
    return 'S';
}
else{
    return 'N';
}
}

ads vert

Basic HTML Tables - Layout, HTML Tables, Attributes, Aside, Footer, Tr tag, Td tag, Th tag, Tbody

  Basic HTML Tables - Layout, HTML Tables, Attributes, Aside, Footer, Tr tag, Td tag, Th tag, Tbody < table >      < thead >    ...