XHAENEUNG 답은 정말 잘나오는데...

  • User Avatar
    Twilight

    이렇게 질문드리면 정말 죄송하지만... 할수있는 모든 방법으로 코드를 고쳐보아도 왜 오답이 나오는지 모르겟네요ㅠㅠ
    ~~~ c++
    #include
    #include
    #include
    #include
    #include

    #pragma warning(disable:4996)
    using namespace std;
    map mNumber;

    void initNumberMap()
    {
    mNumber.clear();

    mNumber.insert(pair<string, int>("zero", 0));
    mNumber.insert(pair<string, int>("one", 1));
    mNumber.insert(pair<string, int>("two", 2));
    mNumber.insert(pair<string, int>("three", 3));
    mNumber.insert(pair<string, int>("four", 4));
    mNumber.insert(pair<string, int>("five", 5));
    mNumber.insert(pair<string, int>("six", 6));
    mNumber.insert(pair<string, int>("seven", 7));
    mNumber.insert(pair<string, int>("eight", 8));
    mNumber.insert(pair<string, int>("nine", 9));
    mNumber.insert(pair<string, int>("ten", 10));
    

    }
    int operator + (const string& strDst, const string& strSrc)
    {
    int nResult = mNumber[strDst] + mNumber[strSrc];
    return nResult;
    }
    int operator - (const string& strDst, const string& strSrc)
    {
    int nResult = mNumber[strDst] - mNumber[strSrc];
    return nResult;
    }
    int operator * (const string& strDst, const string& strSrc)
    {
    int nResult = mNumber[strDst] * mNumber[strSrc];
    return nResult;
    }
    string getStringformInt(int nResult)
    {
    auto iter = mNumber.begin();

    while (iter != mNumber.end())
    {
        if (iter->second == nResult)
        {
            return iter->first;
        }
        iter++;
    }
    return NULL;
    

    }
    int compareString(const void* cDst, const void* cSrc)
    {
    return strcmp((char*)cDst, (char*)cSrc);
    }
    int main()
    {
    initNumberMap();
    string strInput[2] = { "", };
    string strResult[2] = { "", };
    strResult[0].resize(10);

    char cOperator[2] = {};
    int nInput = 0;
    int nResult = 0;
    
    cin >> nInput;
    
    while (nInput--)
    {
        for (int i = 0; i < 2; i++)
        {
            strInput[i].clear();
            strResult[i].clear();
        }
    
        cin >> strInput[0] >> cOperator[0] >> strInput[1] >> cOperator[1] >> strResult[0];
    
    
        //연산문자 예외처리
        for (int i = 0; i < 2; i++)
        {
            if (!mNumber[strInput[i]] && strInput[i] != "zero")
            {
                return 0;
            }
        }
    
        switch (cOperator[0])
        {
        case '+':
            nResult = strInput[0] + strInput[1];
            break;
        case '-':
            nResult = strInput[0] - strInput[1];
            break;
        case '*':
            nResult = strInput[0] * strInput[1];
            break;
        default:
            return 0;
        }
    
        //등호 예외처리
        if (cOperator[1] != '=')
        {
            return 0;
        }
    
        //길이가 10을 넘지않는 알파벳 소문자 보장
        if (strResult[0].size() > 10)
        {
            return 0;
        }
        const char* szInput = strResult[0].c_str();
        for (unsigned int i = 0; i < strResult[0].size(); i++)
        {
            if ('a' > szInput[i] || szInput[i] > 'z')
            {
                return 0;
            }
        }
    
    
        if (0 > nResult || nResult > 10)
        {
            cout << "No" << endl;
        }
        else
        {
            strResult[1] = getStringformInt(nResult);
    
            for (int i = 0; i < 2; i++)
            {
                qsort((char*)strResult[i].c_str(), strResult[i].size(), sizeof(char), compareString);
            }
    
            if (!strResult[0].compare(strResult[1]))
            {
                cout << "Yes" << endl;
            }
            else
            {
                cout << "No" << endl;
            }
        }
    
    }
    
    return 0;
    

    }
    ~~~


    10년 전
2개의 댓글이 있습니다.
  • User Avatar
    LNH

    연산자에 / 를 넣어보세요
    No가 떠야하는데 아무것도 안뜨고 넘어가집니다.
    아마 그래서 오답으로 인식하는게 아닌가 싶은데요


    10년 전 link
  • User Avatar
    lerin

    저도 질문자님이랑 같은 상황이었는데 LNH님 댓글보고 혹시나 하고 / 넣었는데 진짜 되네요 ㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠ 와 진짜 LNH님 감사해용


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