Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Municipiu_Problema_2_Palindrome
import java.util.*; import java.lang.*; class Rextester { public static void main(String args[]) { Scanner in = new Scanner(System.in); String string = in.nextLine(); char[] s = string.toCharArray(); int counter = 0; String max = ""; String temp = ""; while (s != "") { while ( s.charAt(counter) != ' ' ){ temp += s.charAt(counter); if (isPalindrome(temp) && (s.charAt(counter+1) == ' ') && isBigger(temp, max) ) max = temp; counter++; } s = delete(s,0,counter); LOG(s); } LOG("*" + max); } public static boolean isBigger(String first, String second){ boolean result = true; for ( int i = 0; i < first.length(); i++){ for ( int j = 0; j < second.length(); j++){ if ( first.charAt(i) < second.charAt(j) ){ result = false; break; } } if (!result) break; } return result; } public static void LOG(String message){ System.out.println("LOG: " + message); } public static String delete(String value, int first_pos, int last_pos){ String result = ""; for (int i = 0; i < value.length(); i++){ if (( i >= first_pos ) && ( i <= last_pos )) continue; result += value.charAt(i); } return result; } public static boolean isPalindrome(String s) { int n = s.length(); for (int i = 0; i < (n/2); ++i) { if (s.charAt(i) != s.charAt(n - i - 1)) { return false; } } return true; } }
run
|
edit
|
history
|
help
0
piglatin
2A
Rakibul Haque
LunarLanding.java
a+b
detect cycle in singly linked list
Magic No.
linkl
Has A
Word Destructor