Wednesday, March 20, 2013

The Great Indian Programming League 2013 - March Edition Level:Medium

Here is the Link of question and description of 

Four Persons


I am providing you the solution of the above question.


Mybest score on this is 99.99.



Repost Code with better one.(Download COde)
cvcv

____________________________________________________________



 

  1. public class InterchangePosition {


  2. /**

  3. * @param args

  4. */

  5. public static void main(String[] args) {

  6. // TODO Auto-generated method stub

  7. String []arr = {"5#1","6#1","5#3"};

  8. long x1 = System.currentTimeMillis();

  9. System.out.println(get_height(arr));

  10. long x2 = System.currentTimeMillis();

  11. System.out.println("TIme in milli "+(x2-x1));

  12. }

  13. public static int get_height(String[] input1)

  14.     {

  15.         //Write code here


  16. int count=0;


  17. int f[] = new int[input1.length];


  18. int value=0;

  19. String s[]= new String[2];


  20. if(input1.length==0)

  21. return 0;


  22. for(int i=0;i

  23. {


  24. if(Integer.parseInt(((s=input1[i].split("#"))[0]))<4 || Integer.parseInt(s[0])>7

  25. || Integer.parseInt(s[1])<0 || Integer.parseInt(s[1])>11

  26. )

  27. {

  28. //System.out.println("boom1");

  29. return -1;

  30. }



  31. f[i] = (Integer.parseInt(s[0])) * 12 +  Integer.parseInt(s[1]);



  32. }



  33. for(int i : f)

  34. {

  35. System.out.println(""+i);

  36. }

  37. System.out.println("--------------");



  38. for(int i=0;i<f.length;i++)

  39. {

  40. for(int j=i+1;j<f.length;j++)

  41. {



  42. if(f[i]>f[j])

  43. {

  44. //System.out.println("I am in "+f[i]);

  45. count++;

  46. }

  47. }

  48. }

  49. return count;

  50.     }


  51. }


____________________________________________________________

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;
}

}





___________________________________________________________

Download Code: Click Here

Mirror: Click Here






0 comments: