import java.util.Scanner; /* * Recognizes words of a and b, with ñ in center */ public class Palindrom { public static void main(String[] args) { Scanner sc=new Scanner(System.in); Stack<Character> st = new Stack<Character>(); String input = sc.nextLine(); char ch = '0'; int i = 0; while(i < input.length() && (ch = input.charAt(i)) == 'a' || ch == 'b') { st.push(ch); i++; } if(i == input.length() || ch != 'c') System.out.println("Word not recognized"); else if(ch == 'c') { // continue recognizing i++; try { while(i < input.length() && (ch = input.charAt(i)) == 'a' || ch == 'b') { if(ch != st.pop()) { System.out.println("Word not recognized"); return; } i++; } } catch(EmptyStackException e) { System.out.println("Word not recognized"); return; } if(i == input.length() && st.empty()) System.out.println("Word recognized"); else System.out.println("Word not recognized"); } } }