ANAGRAM 문제 질문좀 드립니다 ㅡㅜ

  • HyeokJong
    HyeokJong

    import java.util.Scanner;

    public class Main {

    /**
     * @param args
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int c = sc.nextInt();
        String inputChar, inputChar2;
    
        while (c-- > 0) {
            Boolean result = true;
            inputChar = sc.next();
            inputChar2 = sc.next();
            char tmp;
            if (inputChar.length() != inputChar2.length())
                result = false;
            if (result) {
                char[] input1 = new char[inputChar.length()];
                char[] input2 = new char[inputChar2.length()];
                for (int count = 0; count < inputChar.length(); count++)
                    input1[count] = inputChar.charAt(count);
                for (int count = 0; count < inputChar2.length(); count++)
                    input2[count] = inputChar2.charAt(count);
    
                for (int count1 = 0; count1 < input1.length; count1++) {
                    for (int count2 = 0; count2 < input1.length; count2++) {
                        if ((int) input1[count1] > (int) input1[count2]) {
                            tmp = input1[count1];
                            input1[count1] = input1[count2];
                            input1[count2] = tmp;
                        }
                    }
                }
                for (int count1 = 0; count1 < input1.length; count1++) {
                    for (int count2 = 0; count2 < input1.length; count2++) {
                        if ((int) input2[count1] > (int) input2[count2]) {
                            tmp = input2[count1];
                            input2[count1] = input2[count2];
                            input2[count2] = tmp;
                        }
                    }
                }
                for(int count = 0; count < inputChar.length();count++)
                {
                    if(input1[count]!=input2[count])
                    {
                        result = false;
                        break;
                    }
                }
            }
            if (result)
                System.out.println("Yes");
            else
                System.out.println("No.");
        }
    
    }

    }

    코..코드가 더럽긴한데 이게 왜 계속 오답이 나올까요...
    문제 이해를 잘 못해서 그럴까요 ㅠㅠ... 컴파일을 돌려서 몇가지 테스트 해보면 결과가 맞는것 같긴한데 ..

    인터넷이 안되서 인터넷좀 고치느라 지금 답글 보네요....
    알고리즘이
    1. 입력한 두 문자열의 길이가 다르면 No. 출력
    2. 입력한 두 문자열의 길이가 같을 경우 두 문자열을 정렬한다음 비교
    3. 비교한 문자열이 같을 경우 Yes 출력, 다를 경우 No. 출력
    입니다.


    11년 전
2개의 댓글이 있습니다.
  • JongMan
    JongMan

    코드 복붙 대신 알고리즘을 설명해 주세요~~


    11년 전 link
  • kwangswei
    kwangswei

    방금 풀어보니 문제를 다시 한 번 꼼꼼이 읽어보시면 금방 해결 하실 수 있으실 것 같습니다!


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