ANAGRAM 질문있습니다

  • 오산돌구
    오산돌구

    안녕하세요.

    거침없이 문제푸시는 분들을 동경하면서, 오늘도 오답~!! 을 연발하는
    초보입니다.

    ANAGRAM을 풀고있습니다.

    device에 해당하는 알파벳 plus해주고
    password에 해당하는 알파벳 minus해주는 단순한 로직인데요.
    틀리네요;;

    제가 놓치고 있는것같은데 귀뜸해주시면 감사하겠습니다.

    아래는 제출한 코드에요.~~

    그나저나 Corea님...무섭네요....연속정답.덜덜

    test_case = gets
    
    alpha  = Hash.new(0)
    (1..test_case.to_i).each {
        alpha.clear
        data = gets.split(' ')
    
        data[0].chars{
        |char|
            if alpha[char] == nil
                alpha[char] = 0
            end
            alpha[char] = alpha[char] + 1
        }
    if data[0].length != data[1].length
        puts "No."
        next
    end
    failed = 0
        data[1].chars{
        |char|
            if alpha[char] == nil || alpha[char] == 0
                failed = 1
                break
            else
                alpha[char] = alpha[char] - 1
            end
        }
        if failed == 0
            puts "Yes"
        elsif failed == 1
            puts "No."
        end
    }
    

    11년 전
3개의 댓글이 있습니다.
  • Corea
    Corea

    문제 설명을 확인하세요!

    아래에 중요한 부분을 써두고 갈게요 ㅎㅎ

    Wookayin, the tech lead of iWook, decided that the password for a iWook device must use all letters from the device’s serial number exactly once in a case-sensitive way, and not in the same order (Obviously, in the real world, it’s a faily bad security practice to enforce such restrictions to passwords.)


    11년 전 link
  • 오산돌구
    오산돌구

    알려주신 중요한부분 처리했더니 바로됐네요. 정답맞추고 Being님이
    작성하신 ruby소스보고 다시한번 좌절......ㅋㅋㅋ

    Corea님 감사해요~~ : )


    11년 전 link
  • Being
    Being

    그냥 숏코딩 하고 노는 거죠 ㅠ


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