nageshtikare
BAN USERSo u were provided with input of words.. in which u need to tell whether the word(s) is/are anagram of ABC or not..? I am right.?
- nageshtikare September 27, 2014import java.util.Scanner;
public class Mice {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int T = Integer.parseInt(input.nextLine());
String[] nm;
int n;
int m;
int[] mices;
int[] holes;
int[] distances;
int[] differences;
String[] miceStr;
String[] holesStr;
for(int i = 0; i < T; i++) {
nm = input.nextLine().split(" ");
n = Integer.parseInt(nm[0]);
m = Integer.parseInt(nm[1]);
mices = new int[n];
holes = new int[m];
distances = new int[n];
differences = new int[m];
miceStr = input.nextLine().split(" ");
for(int j = 0; j < miceStr.length; j++) {
mices[j] = Integer.parseInt(miceStr[j]);
}
holesStr = input.nextLine().split(" ");
for(int j = 0; j < holesStr.length; j++) {
holes[j] = Integer.parseInt(holesStr[j]);
}
for(int mice = 0; mice < mices.length; mice++) {
for(int hole = 0; hole < holes.length; hole++) {
differences[hole] = getDifference(mices[mice], holes[hole]);
}
distances[mice] = getMin(differences);
}
System.out.println(getMax(distances));
}
}
private static int getDifference(int i, int j) {
if(i < j) {
return j - i;
} else
return i - j;
}
private static int getMin(int[] num) {
int min = 0;
if(num.length > 0)
min = num[0];
if(num.length > 1)
for(int i = 1; i < num.length; i++) {
if(num[i] < min)
min = num[i];
}
return min;
}
private static int getMax(int[] num) {
int max = 0;
if(num.length > 0)
max = num[0];
if(num.length > 1)
for(int i = 1; i < num.length; i++) {
if(num[i] > max)
max = num[i];
}
return max;
}
}
import java.util.ArrayList;
- nageshtikare September 28, 2014public class Sentence {
public static void main(String[] args) {
ArrayList<String> words = new ArrayList<String>();
words.add("this");
words.add("some");
words.add("is");
words.add("a");
words.add("sentence");
words.add("the");
words.add("an");
String string = "thisisasentence";
String out = "";
char[] strChar = string.toCharArray();
String temp = "";
for(int i = 0; i < strChar.length; i++) {
temp = temp + strChar[i];
if(words.contains(temp)) {
out = out + " " + temp;
temp = "";
}
}
System.out.println(out);
}
}