LECTURE 관련 오답처리 질문 드립니다.

  • quna
    quna

    LECTURE 관련해서, 입력, 출력 컴파일 잘 되었는데 무엇이 문제 인지 잘 모르겠습니다.

    추가적인 테스트 케이스가 무엇이 있을까요?

    #include <iostream>
    #include <cstring>
    #include <map>
    
    using namespace std;
    
    typedef unsigned int UINT;
    
    const int BUF_MAX = 1000;
    const int COPY_SIZE = 2;
    
    char* SortString(char * _ch)
    {
        static char* g_szOut = NULL;
    
        multimap<int, char*> Dest;
    
        for( UINT i = 0 ; i < strlen(_ch) ; i += 2 )
        {
            char* szBuf = new char[2];
            szBuf[0] = _ch[i];
            szBuf[1] = _ch[i+1];
            Dest.insert(make_pair(_ch[i]*10+_ch[i+1], szBuf));
        }
    
        char szBuf[BUF_MAX + 1] = { 0 };
        multimap<int, char*>::iterator it = Dest.begin();
    
        int idx = 0;
    
        for( it ; it != Dest.end() ; ++it )
        {
            memcpy(&szBuf[idx], it->second, COPY_SIZE);
            idx+=2;
    
            delete it->second;
            it->second = NULL;
        }
        Dest.clear();
    
        g_szOut = szBuf;
    
        return g_szOut;
    }
    
    int main()
    {
        int iCnt = 0;
    
        cin >> iCnt;
    
        for( int i = 0 ; i < iCnt ; ++i )
        {
            char szBuf[BUF_MAX + 1] = { 0 };
    
            cin >> szBuf;
    
            cout << SortString(szBuf) << endl;
        }
    
        return 0;
    }
    

    8년 전
2개의 댓글이 있습니다.
  • Neon
    Neon

    Test case baaz
    Expected result : azba
    Your result : baaz


    7년 전 link
  • Neon
    Neon

    그리고 제컴에서 돌려보니 메모리문제라도 있나 이상한 문자가 나올 때도 있네요.


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