Here is the Link of question and description of
___________________________________________________________
Four Persons
I am providing you the solution of the above question. My best score on this is 99.99.
Repost Code with better one.(Download COde)
____________________________________________________________
____________________________________________________________
Another One
Download Code: Click Here
____________________________________________________________
- public class InterchangePosition {
- /**
- * @param args
- */
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- String []arr = {"5#1","6#1","5#3"};
- long x1 = System.currentTimeMillis();
- System.out.println(get_height(arr));
- long x2 = System.currentTimeMillis();
- System.out.println("TIme in milli "+(x2-x1));
- }
- public static int get_height(String[] input1)
- {
- //Write code here
- int count=0;
- int f[] = new int[input1.length];
- int value=0;
- String s[]= new String[2];
- if(input1.length==0)
- return 0;
- for(int i=0;i
- {
- if(Integer.parseInt(((s=input1[i].split("#"))[0]))<4 || Integer.parseInt(s[0])>7
- || Integer.parseInt(s[1])<0 || Integer.parseInt(s[1])>11
- )
- {
- //System.out.println("boom1");
- return -1;
- }
- f[i] = (Integer.parseInt(s[0])) * 12 + Integer.parseInt(s[1]);
- }
- for(int i : f)
- {
- System.out.println(""+i);
- }
- System.out.println("--------------");
- for(int i=0;i<f.length;i++)
- {
- for(int j=i+1;j<f.length;j++)
- {
- if(f[i]>f[j])
- {
- //System.out.println("I am in "+f[i]);
- count++;
- }
- }
- }
- return count;
- }
- }
____________________________________________________________
Another One
Download Code: Click Here
Mirror: Click Here
___________________________________________________________
public class InterchangePosition {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String []arr = {"5#5","6#6","5#5","6#6","5#11"};
long x1 = System.currentTimeMillis();
System.out.println(get_height(arr));
long x2 = System.currentTimeMillis();
System.out.println("TIme in milli "+(x2-x1));
}
public static int get_height(String[] input1)
{
//Write code here
int count=0;
int f[] = new int[input1.length];
int value=0;
if(input1.length==0)
return 0;
try
{
for(int i=0;i {
if(Integer.parseInt(input1[i].substring(0, input1[i].indexOf('#')))<4 ||
Integer.parseInt(input1[i].substring(0, input1[i].indexOf('#')))>7)
{
//System.out.println("boom1");
return -1;
}
if(Integer.parseInt(input1[i].substring(input1[i].indexOf('#')+1))<0 ||
Integer.parseInt(input1[i].substring(input1[i].indexOf('#')+1))>11)
{
//System.out.println("boom2");
return -1;
}
value = (Integer.parseInt(input1[i].substring(0, input1[i].indexOf('#')))) * 12 + Integer.parseInt(input1[i].substring(input1[i].indexOf('#')+1));
f[i] = value;
}
}
catch(NumberFormatException nf)
{
nf.printStackTrace();
return -1;
}
for(int i : f)
{
System.out.println(""+i);
}
System.out.println("--------------");
for(int i=0;i <f.length;i++) {
for(int j=i+1;j <f.length;j++) {
if(f[i]>f[j])
{
//System.out.println("I am in "+f[i]);
count++;
}
}
}
return count;
}
}
public class InterchangePosition {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String []arr = {"5#5","6#6","5#5","6#6","5#11"};
long x1 = System.currentTimeMillis();
System.out.println(get_height(arr));
long x2 = System.currentTimeMillis();
System.out.println("TIme in milli "+(x2-x1));
}
public static int get_height(String[] input1)
{
//Write code here
int count=0;
int f[] = new int[input1.length];
int value=0;
if(input1.length==0)
return 0;
try
{
for(int i=0;i
if(Integer.parseInt(input1[i].substring(0, input1[i].indexOf('#')))<4 ||
Integer.parseInt(input1[i].substring(0, input1[i].indexOf('#')))>7)
{
//System.out.println("boom1");
return -1;
}
if(Integer.parseInt(input1[i].substring(input1[i].indexOf('#')+1))<0 ||
Integer.parseInt(input1[i].substring(input1[i].indexOf('#')+1))>11)
{
//System.out.println("boom2");
return -1;
}
value = (Integer.parseInt(input1[i].substring(0, input1[i].indexOf('#')))) * 12 + Integer.parseInt(input1[i].substring(input1[i].indexOf('#')+1));
f[i] = value;
}
}
catch(NumberFormatException nf)
{
nf.printStackTrace();
return -1;
}
for(int i : f)
{
System.out.println(""+i);
}
System.out.println("--------------");
for(int i=0;i
if(f[i]>f[j])
{
//System.out.println("I am in "+f[i]);
count++;
}
}
}
return count;
}
}
Download Code: Click Here
Mirror: Click Here

0 comments:
Post a Comment