mngsh1
BAN USER/**
*
*/
package Amazon;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
/**
* @author mangesh
*
*/
public class GenerateMAX {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Integer a[] = { 4,2,1,1,0 };
LinkedList<Integer> list = new LinkedList<Integer>(Arrays.asList(a));
ArrayList<Long> max = new ArrayList<Long>();
Collections.sort(list);
if (list.get(0) != 0) {
System.out.println("Can not find such number!!!");
return;
}
int k = 1;
int nocosiderDigit = -1;
boolean remove = false;
while (true) {
long number = list.get(0);
int pow = 1;
for (int i = 1; i < list.size(); i++) {
if (nocosiderDigit == i)
continue;
number += (long) (list.get(i) * Math.pow(10, pow++));
}
if (number % 3 == 0) {
max.add(number);
}
while (true) {
if (list.get(k) % 3 != 0) {
if (!remove)
nocosiderDigit = list.indexOf(list.get(k));
else
list.remove(k);
k++;
break;
}
k++;
if (k >= list.size())
break;
}
if (k >= list.size()) {
if (max.size() == 0 && !remove) {
k = 1;
remove = true;
} else {
break;
}
}
}
if (max.size() > 0) {
Collections.sort(max);
System.out.println(max.get(max.size() - 1));
System.out.println(max.toString());
} else
System.out.println("Can not find such number!!!");
}
}
/**
*
*/
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
/**
* @author mangesh
*
*/
public class GenerateMAX {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Integer a[] = { 1, 2, 4, 5, 6, 1, 0 ,9,2,0};
LinkedList<Integer> list = new LinkedList<Integer>(Arrays.asList(a));
Collections.sort(list);
if (list.get(0) != 0) {
System.out.println("Can not find such number!!!");
return;
}
int k = 1;
while (true) {
long number = list.get(0);
for (int i = 1; i < list.size(); i++) {
number += (long) (list.get(i) * Math.pow(10, i));
}
if (number % 3 == 0) {
System.out.println(number);
return;
}
while (true) {
if(list.get(k) % 3!= 0){
list.remove(k);
break;
}
k++;
if (k >= list.size())
break;
}
if (k >= list.size())
break;
}
System.out.println("Can not find such number!!!");
}
}
/**
*
*/
package Amazon;
import java.io.ObjectInputStream.GetField;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
/**
* @author mangesh
*
*/
public class SortTwoTuples {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Object[][] a = { { 'a', 1, 5 }, { 'b', 2, 4 }, { 'c', 7, 8 } };
FindSorted(a);
}
public static void FindSorted(Object[][] a) {
LinkedList<Tuple> p = new LinkedList<Tuple>();
LinkedList<Tuple> finalL = new LinkedList<Tuple>();
// ArrayList<Tuple> p = new ArrayList<Tuple>();
for (int i = 0; i < a.length; i++) {
p.add(new Tuple('2', a[i][2]));
// a[i][0]
}
Collections.sort(p);
//System.out.println(p.toString());
int cnt3 = 0;// for tuple 3
int cnt2 = 0;// for tuple 2
while (true) {
if ((Integer) (a[cnt2][1]) <= p.get(cnt3).val) {
finalL.add(new Tuple(a[cnt2][0], a[cnt2][1]));
cnt2++;
if (cnt2 >= a.length)
break;
} else {
finalL.add(p.get(cnt3));
cnt3++;
if (cnt3 >= a.length)
break;
}
}
while (cnt2 < a.length) {
finalL.add(new Tuple(a[cnt2][0], a[cnt2][2]));
cnt2++;
}
while (cnt3 < a.length) {
finalL.add(p.get(cnt3));
cnt3++;
}
System.out.println(finalL.toString());
}
}
class Tuple implements Comparable<Tuple> {
char name;
Integer val;
public Tuple() {
}
public Tuple(Object a, Object a2) {
name = (char) a;
val = (int) a2;
}
/*
* (non-Javadoc)
*
* @see java.lang.Comparable#compareTo(java.lang.Object)
*/
@Override
public int compareTo(Tuple o) {
return this.val.compareTo(o.val);
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
// TODO Auto-generated method stub
return "[" + name + "," + val + "]";
}
// public boolean equals(Object o) {
// if (o instanceof Tuple) {
// // id comparison
// Tuple mo = (Tuple) o;
// return mo.val.equals(val);
// }
// return false;
// }
}
/**
*
*/
package Amazon;
/**
* @author mangesh
*
*/
public class MaxProduct {
/**
* @param args
*/
static int max1 = 0;
static int max2 = 0;
static int max3 = 0;
static int negativecnt = 0;
public static void main(String[] args) {
// TODO Auto-generated method stub
int a[] = { 0, 1, 3, 100, -70, 5 };
for (int i = 0; i < a.length; i++) {
if (Math.abs(max1) < Math.abs(a[i])) {
max2 = max1;
max1 = a[i];
}
if (Math.abs(a[i]) < Math.abs(max1)) {
if (Math.abs(max2) < Math.abs(a[i])) {
max3 = max2;
max2 = a[i];
}
if (Math.abs(a[i]) < Math.abs(max2)) {
if (Math.abs(max3) < Math.abs(a[i])) {
max3 = a[i];
}
}
}
}
negativecnt = 0;
if (max1 < 0)
negativecnt++;
if (max2 < 0)
negativecnt++;
if (max3 < 0)
negativecnt++;
// System.out.println(negativecnt+"Two no are:" + max1 + "," + max2 +
// "," + max3+ "\n Product:" + max1 * max2 * max3);
if (negativecnt == 3) {
int max = findMax(a, 0, 0);
max3 = max;
} else if (negativecnt == 1) {
int max;
if (max1 < 0) {
max = findMax(a, max2, max3);
max1 = max;
} else if (max2 < 0) {
max = findMax(a, max1, max3);
max2 = max;
} else {
max = findMax(a, max1, max2);
max3 = max;
}
}
System.out.println("Two no are:" + max1 + "," + max2 + "," + max3
+ "\n Product:" + max1 * max2 * max3);
}
static int findMax(int a[], int exclude1, int exclude2) {
int max = Integer.MIN_VALUE;
for (int i = 0; i < a.length; i++) {
if (a[i] > max && a[i] != exclude1 && a[i] != exclude2)
max = a[i];
}
return max;
}
int[] FindHighestTwo() {
int[] b = new int[2];
return b;
}
}
Actually answer should be 8760 .....
- mngsh1 September 27, 2014