답안 #251368

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
251368 2020-07-21T04:22:55 Z dwsc Password (RMI18_password) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
vector<string> mergevector(vector<string> v){
    vector<string> newvector;
    for (int i = 0; i < v.size(); i+= 2){
        if (i == v.size()-1){
            newvector.push_back(v[i]);
            break;
        }
        string s1 = v[i],s2 = v[i+1];
        //cout << s1 << " " << s2 << "hi\n";
        string newstring = s1;
        int insertionpos = 0;
        int curpos = 0;
        while (curpos < s2.length()){
            string temp = "";
            for (int j = 0; j < newstring.length(); j++){
                if (j == insertionpos) temp += s2[curpos];
                temp += newstring[j];
            }
            if (insertionpos == newstring.length()) temp += s2[curpos];
            if (query(temp) == temp.size()){
                newstring = temp;
                curpos++;
                insertionpos++;
            }
            else{
                insertionpos++;
            }
        }
        //cout << newstring << "\n";
        newvector.push_back(newstring);
    }
    return newvector;
}
string guess(int n, int s){
    vector<string> letters;
    for (int i = 0; i < s; i++){
        int ans = 0;
        char c = (char)(i+97);
        string act = "";
        for (int j = 1; j <= n; j++){
            string temp = act+c;
            if (query(temp) == ans) break;
            act = temp;
            ans++;
        }
        //cout << act << "\n";
        if (ans) letters.push_back(act);
    }
    while (letters.size() > 1)letters = mergevector(letters);
    return letters[0];
}

Compilation message

password.cpp: In function 'std::vector<std::__cxx11::basic_string<char> > mergevector(std::vector<std::__cxx11::basic_string<char> >)':
password.cpp:5:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < v.size(); i+= 2){
                     ~~^~~~~~~~~~
password.cpp:6:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (i == v.size()-1){
             ~~^~~~~~~~~~~~~
password.cpp:15:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         while (curpos < s2.length()){
                ~~~~~~~^~~~~~~~~~~~~
password.cpp:17:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (int j = 0; j < newstring.length(); j++){
                             ~~^~~~~~~~~~~~~~~~~~~~
password.cpp:21:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if (insertionpos == newstring.length()) temp += s2[curpos];
                 ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
password.cpp:22:17: error: 'query' was not declared in this scope
             if (query(temp) == temp.size()){
                 ^~~~~
password.cpp: In function 'std::__cxx11::string guess(int, int)':
password.cpp:44:17: error: 'query' was not declared in this scope
             if (query(temp) == ans) break;
                 ^~~~~