Hi
I wrote this code for 8132. Street Trees
Problem code: STREETR
i get wrong answer though i tested it against possible test cases in my mind ..
can some body help please ????
import java.util.Scanner;
public class Main
{
public static void main (String args[])
{
int noofTree=0;
int counter=0;
Scanner scan= new Scanner(System.in);
// System.out.print("Enter the No of Trees\n");
try{
noofTree= scan.nextInt();
}
catch(NumberFormatException nfe)
{
nfe.printStackTrace();
}
int []anArray;
// System.out.print("Enter the Co-ordinates\n");
anArray= new int[100];
if(noofTree>=3)
{
for (int i=0;i<noofTree;i++)
{
try{
anArray[i]=scan.nextInt();
}
catch(NumberFormatException nfe)
{
nfe.printStackTrace();
}
System.out.print(anArray[i]);
}
}
int i=0;
int k=1;
int diff=0;
int max=0;
max=anArray[--noofTree];
diff=anArray[k]-anArray[i];
// System.out.print("Diff="+diff);
k=1;
loop: for(int no=diff;no>0;no--)
{
int var=anArray[i];
while(var<=max)
{
var+=no;
if(var>max)
{
counter=0;
k=1;
continue loop;
}
if(var!=(anArray[k]))
{
counter++;
}
if (var==anArray[k])
{
if(var==max)
{
System.out.print("\n"+counter);
System.exit(0);
}
if(var<=anArray[k])
{
k++;
}
}
}
}
}
}
created
last reply
- 1
reply
- 232
views
- 2
users