Need help in CODETOWN problem

Approach

In the given problem statement, I have postulated that in the context of a vowel, the binary digit ‘1’ is assigned, and ‘0’ in the case of a consonant. Consequently, the string ‘CODETOWN’ transforms into the binary representation → 01010100(84). Subsequently, I proceed to convert the provided string into a binary representation using the aforementioned logic. Lastly, I apply the bitwise AND operation with ‘01010100’ (84) and the derived binary string. If the result of the bitwise AND operation is equal to 84, then the program outputs ‘YES’; otherwise, it outputs ‘NO.’

It fails some test cases. If anyone could have a look into this, it would be grateful and appreciated.

Here is my code.

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

public class Main {
    public static void main(String[] args) throws java.lang.Exception {
        Scanner sc = new Scanner(System.in);
        int test = sc.nextInt();
        while (test != 0) {
            int codetown = 84;
            String a = sc.next();
            int total = 0, start = 1;
            for (int i = a.length() - 1; i >= 0; i--) {
                if (a.charAt(i) == 'A' || a.charAt(i) == 'E' || a.charAt(i) == 'I' || a.charAt(i) == 'O'|| a.charAt(i) == 'U') {
                    total += start;
                }
                start = start * 2;
            }
            //System.out.println(Integer.toBinaryString(total));
            if ((codetown & total) == codetown)
                System.out.println("YES");
            else
                System.out.println("NO");
            test--;
        }
        sc.close();
    }
}

Problem Link: Reach Codetown Practice Coding Problem - CodeChef

CODEEOWN should give NO but your code will give YES.

You can figure out the reason :slight_smile:

Hi crypter472,

Thank you for helping me out. If anybody is looking for the correct code, here it is

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

public class Main {
    public static void main(String[] args) throws java.lang.Exception {
        Scanner sc = new Scanner(System.in);
        int test = sc.nextInt();
        while (test != 0) {
            int codetown = 84;
            String a = sc.next();
            int total = 0, start = 1;
            for (int i = a.length() - 1; i >= 0; i--) {
                if (a.charAt(i) == 'A' || a.charAt(i) == 'E' || a.charAt(i) == 'I' ||a.charAt(i) == 'O'|| a.charAt(i) == 'U') {
                    total += start;
                }
                start = start * 2;
            }
            int ans=(codetown ^ total);
            if (ans == 0)
                System.out.println("YES");
            else
                System.out.println("NO");
            test--;
        }
        sc.close();
    }
}