Saturday, May 3, 2014

StartUp [Coder-Strike 2014 - Finals (online edition, Div. 1)] Problem A

A. Start Up
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it?
The market analysts came up with a very smart plan: the name of the company should be identical to its reflection in a mirror! In other words, if we write out the name of the company on a piece of paper in a line (horizontally, from left to right) with large English letters, then put this piece of paper in front of the mirror, then the reflection of the name in the mirror should perfectly match the line written on the piece of paper.
There are many suggestions for the company name, so coming up to the mirror with a piece of paper for each name wouldn't be sensible. The founders of the company decided to automatize this process. They asked you to write a program that can, given a word, determine whether the word is a 'mirror' word or not.
Input
The first line contains a non-empty name that needs to be checked. The name contains at most 105 large English letters. The name will be written with the next sans serif font:


Output
Print 'YES' (without the quotes), if the given name matches its mirror reflection. Otherwise, print 'NO' (without the quotes).

Sample test(s)
input
AHA
output
YES
input
Z
output
NO
input
XO
output
NO
My Solution [ Java ] :
→ Source
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class StartUpMirror {
    public static void main(String[] args){
        Scanner s = new Scanner(System.in);
        String st = s.next();
        StringBuffer rev = new StringBuffer();
        Set<Character> set = new HashSet<Character>(Arrays.asList('A','H','I','M','O','T','U','V','W','X','Y'));
        
        for(int i=0;i<st.length();++i){
            if(!set.contains(st.charAt(i))){System.out.println("NO");System.exit(0);}
            rev.append(st.charAt(i));
        }
        if(st.matches(rev.reverse().toString()))
        System.out.println("YES");
        else
        System.out.println("NO");
    }
}

No comments:

Post a Comment