(UVA) Abstract Names - Solution

Link to the problem: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=2760
 

import java.io.*;
import java.util.*;

class Main {
    public void process() throws NumberFormatException, IOException {
        Scanner sc = new Scanner(System.in);
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));

        int numTests = sc.nextInt();
        for (int test = 0; test < numTests; test++) {
            String s1 = sc.next();
            String s2 = sc.next();
           
            boolean same = true;
           
            if (s1.length() != s2.length()) {
                same = false;
            }
           
            String vowels = "aeiou";
            for (int i = 0; i < s1.length() && same; i++) {
                if (vowels.indexOf(s1.charAt(i)) == -1) { // it is a consonant
                    if (s1.charAt(i) != s2.charAt(i)) { // if one is consonant, the other needs to be exactly the same
                        same = false;
                    }
                }
                else { // it is a vowel
                    if (vowels.indexOf(s2.charAt(i)) == -1) { // it is a consonant
                        same = false;
                    }
                }
            }

            String answer = same ? "Yes\n" : "No\n";
            bw.write(answer);
        }
                                                      
        bw.flush();
        bw.close();
       
        return;
    }
   
    public static void main(String[] args) throws NumberFormatException, IOException {
        Main m = new Main();
        m.process();
       
        System.exit(0);
    }
}

Comments

Popular posts from this blog

(Coderbyte) Dash Insert II - Solução

(Coderbyte) Run Length - Solução

(Coderbyte) Counting Minutes I - Solução