[URI]문제 질문입니다.

  • spearkkk
    spearkkk

    ##URI문제 질문입니다.

    우선 문제 밑에 있는 댓글에 있는 고려사항은 다확인하여
    진행해보았습니다.

    하지만 오답으로 뜨고 있습니다.

    문제는 간단합니다 %20같은 인코딩된 문자를 원래 문자로 바꾸는 것입니다.

    반복을 통해 여러 special 문자에 대해 변환과정을 가졌는데
    왜 오답이 나오는지 알지 못하겠습니다.

    #include 
    #include
    
    using namespace std;
    
    string decoding(string str);
    
    int main() {
    int cnt;
    
    cin >> cnt;
    
    for (int i = 0; i < cnt; ++i) {
        string str;
    
        cin >> str;
        cout << decoding(str) << endl;
    }
    return 0;
    }
    
    string decoding(string str) {
    int idx_cur = 0;
    string encoded_strings[17] = { "%20", "%21", "%22","%23","%24", "%25", "%26","%27","%28", "%29", "%2a", "%2b", "%2c", "%2d", "%2e", "%2f"};
    string special_characters[17] = { " ", "!", "\"", "#", "$", "%", "&", "\'", "(", ")", "*", "+", "`", "-", ".", "/"};
    
    for(int i = 0; i < 17; ++i) {
        while (idx_cur < str.length() - 2 & str.length() > 2) {
            if (str.substr(idx_cur, 3).compare(encoded_strings[i]) == 0) {
                string pre = str.substr(0, idx_cur);
                string post = str.substr(idx_cur + 3, str.length());
                str = pre + special_characters[i] + post;
                //cout << pre << " " << post << endl;
            }
            ++idx_cur;
        }
        idx_cur = 0;
    }
    
    return str;
    }
    

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