ANAGRAM 정답은 맞는데 오답이라고 나오는데 조언좀 부탁드립니다

  • harbris
    harbris

    import java.io.IOException;
    import java.util.Scanner;

    public class Main {
    public static void main(String[] args) throws IOException {
    Scanner sc = new Scanner(System.in);

    int cases = sc.nextInt() * 2;
        int count = 0;
        String result ="";
    
        String compare_name = ""; 
        String plag = ""; 
        String last_plag = "";
        while (cases-- > 0) {
            count++;
            String name = sc.next();
            last_plag = "Y";
            if (count == 2) {
                count = 0;
    
                for (int i = 0; i < name.length(); i++) {
                    plag = "N";
    
                    for (int j = 0; j < compare_name.length(); j++) {
                        if (name.charAt(i) == compare_name.charAt(j)) {
                            plag = "Y";
                        }
                    }
                    if (plag == "N" || name.equals(compare_name)) {
                        last_plag = "N";
                    }
                }
    
    
                if (last_plag == "N") {
                    result += "No\n";
    
                }
                if (last_plag == "Y") {
                    result += "Yes\n";
                }
    
            } else {
                compare_name = name;
            }
        }
        System.out.println(result);
    }

    }


    11년 전
1개의 댓글이 있습니다.
  • yougatup
    yougatup

    알고리즘에 문제가 있는 것 같습니다. A AAAAA 를 입력해도 Yes 가 나올 것 같네요..

    그리고 No를 출력할 때 No 가 아니라 No. 라고 되어있습니다(!)


    11년 전 link
  • 정회원 권한이 있어야 커멘트를 다실 수 있습니다. 정회원이 되시려면 온라인 저지에서 5문제 이상을 푸시고, 가입 후 7일 이상이 지나셔야 합니다. 현재 문제를 푸셨습니다.