Friday, November 24, 2017

Odd Gnome Kattis Problem Solution In Java



//Nayeem Shahriar Joy, Applied Physics & Electronic Engineering, University of Rajshahi.
 
import java.util.Scanner;
public class JavaApplication1 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner io=new Scanner(System.in);
int s1=Integer.parseInt(io.nextLine());
for(int i=0;i<s1;i++)
{
String s2=io.nextLine();
String[]values=s2.split(" ");
System.out.println(ans(values));
}
System.out.println();
// TODO code application logic here
}
public static int ans(String[]a)
{
int king=0;
for(int i=1;i<a.length-2;i++)
{
Integer A=Integer.parseInt(a[i]);
Integer B=Integer.parseInt(a[i+1]);
Integer C=Integer.parseInt(a[i+2]);
if(A<C && (A<B && B>C))
{
king=i+1;
break;
}
else if(A<C && (A>B && B<C) )
{
king=i+1;
break;
}
}
return king;
}
}

No comments:

Post a Comment