답안 #333350

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
333350 2020-12-05T16:46:10 Z valerikk Password (RMI18_password) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;

int query(string str);

void myinsert(string &str, int pos, char x) {
    string s = "";
    for (int i = 0; i <= str.size(); i++) {
        if (i < pos) s.push_back(str[i]); else {
            if (i == pos) s.push_back(x); else s.push_back(str[i - 1]);
        }
    }
    str = s;
}

void myerase(string &str, int pos) {
    string s = "";
    for (int i = 0; i < str.size(); i++) {
        if (i == pos) continue;
        s.push_back(str[i]);
    }
    return s;
}

string guess(int n, int s) {
    string cur = "";
    string res = "";
    for (int i = 0; i < n; i++) {
        while (true) {
            bool was = false;
            for (char x = 'a'; x < 'a' + s; x++) {
                myinsert(cur, i, x);
                if (query(cur) == cur.size()) was = true; else myerase(cur, i);
            }
            if (!was) break;
        }
        res.push_back(cur[i]);
    }
    return res;
}

Compilation message

password.cpp: In function 'void myinsert(std::string&, int, char)':
password.cpp:8:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 |     for (int i = 0; i <= str.size(); i++) {
      |                     ~~^~~~~~~~~~~~~
password.cpp: In function 'void myerase(std::string&, int)':
password.cpp:18:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |     for (int i = 0; i < str.size(); i++) {
      |                     ~~^~~~~~~~~~~~
password.cpp:22:12: error: return-statement with a value, in function returning 'void' [-fpermissive]
   22 |     return s;
      |            ^
password.cpp: In function 'std::string guess(int, int)':
password.cpp:33:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |                 if (query(cur) == cur.size()) was = true; else myerase(cur, i);
      |                     ~~~~~~~~~~~^~~~~~~~~~~~~