답안 #848790

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
848790 2023-09-13T13:50:21 Z TahirAliyev Password (RMI18_password) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;

int query(string str);

vector<string> v;

string merge(string a, string b){
    int p1 = 0, p2 = 0;
    string q;
    while(p1 <= a.size() && p2 < b.size()){
        q = a;
        q.insert(q.begin() + p1, b[p2]);
        if(query(q) == q.size()){
            a = q;
            p2++;
        }
        else{
            p1++;
        }
    }
    return a;
}

bool comp(string a, string b){
    return a.size() < b.size();
}

string guess(int n, int s){
    for(char c = 'a'; c <= 'a' + s - 1; c++){
        string s = "";
        for(int i = 1; i <= n; i++){
            s += c;
        }
        int cnt = query(s);
        s = "";
        for(int i = 1; i <= cnt; i++){
            s += c;
        }
        v.push_back(s);
    }
    string s;
    sort(v.begin(), v.end(), comp);
    while(v.size() != 1){
        s = merge(v[0], v[1]);
        v.erase(v.begin());
        v.erase(v.begin() + 1);
        v.push_back(s);
        sort(v.begin(), v.end());
    }
    return v[0];
}

Compilation message

password.cpp: In function 'std::string merge(std::string, std::string)':
password.cpp:12:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |     while(p1 <= a.size() && p2 < b.size()){
      |           ~~~^~~~~~~~~~~
password.cpp:12:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |     while(p1 <= a.size() && p2 < b.size()){
      |                             ~~~^~~~~~~~~~
password.cpp:15:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |         if(query(q) == q.size()){
      |            ~~~~~~~~~^~~~~~~~~~~
password.cpp: In function 'std::string guess(int, int)':
password.cpp:43:12: error: declaration of 'std::string s' shadows a parameter
   43 |     string s;
      |            ^
password.cpp:30:25: note: 'int s' previously declared here
   30 | string guess(int n, int s){
      |                     ~~~~^