답안 #1064766

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1064766 2024-08-18T17:33:01 Z AlgorithmWarrior Password (RMI18_password) C++14
컴파일 오류
0 ms 0 KB
// Sample grader for contestants' use.
//
// Usage: place your input data in the file password.in in the format
//
// line 1: N S
// line 2: hidden_password
//
// Then compile this grader together with your implementation.
// Run the binary to see your guessing strategy at work!
// Set DEBUG to 1 to print all queries.
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
#include <stdlib.h>
#include <assert.h>
#include <queue>
#include <cstring>

using namespace std;

#define DEBUG 0
#define MAX_QUERIES 50000
#define MAX_N 5000
#define MAX_SIGMA 26

static string password;
static int n, s, numQueries;
static stringstream msg;

static void end(int success) {
  cout << (success ? "SUCCESS! " : "ERROR: ") << msg.str() << endl;
  exit(0);
}

int query(string q) {
  
}

class cmp
{
public:
    bool operator()(string a,string b)
    {
        return a.size()>b.size();
    }
};

string guess(int n, int s)
{
    int cnt[300]={0};
    char ch;
    priority_queue<string,vector<string>,cmp>pq;
    for(ch='a';ch<'a'+s;++ch)
    {
        int i;
        string s="";
        for(i=1,s=ch;s.size()<=n && query(s)==s.size();++i,s+=ch);
        cnt[ch]=i-1;
        s.pop_back();
        if(s.size())
            pq.push(s);
    }
    while(pq.size()>1)
    {
        string s1=pq.top(); pq.pop();
        string s2=pq.top(); pq.pop();
        int i,j=0;
        int siz=s1.size();
        int siz2=s2.size();
        string rez="";
        for(i=0;i<=siz;++i)
        {
            while(j<siz2 && query(rez+s2[j]+s1.substr(i,siz-i))==(rez+s2[j]+s1.substr(i,siz-i)).size())
                rez+=s2[j++];
            if(i<siz)
                rez+=s1[i];
        }
        pq.push(rez);
    }
    return pq.top();
}

Compilation message

password.cpp: In function 'int query(std::string)':
password.cpp:38:1: warning: no return statement in function returning non-void [-Wreturn-type]
   38 | }
      | ^
password.cpp: In function 'std::string guess(int, int)':
password.cpp:58:30: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   58 |         for(i=1,s=ch;s.size()<=n && query(s)==s.size();++i,s+=ch);
      |                      ~~~~~~~~^~~
password.cpp:58:45: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |         for(i=1,s=ch;s.size()<=n && query(s)==s.size();++i,s+=ch);
      |                                     ~~~~~~~~^~~~~~~~~~
password.cpp:59:13: warning: array subscript has type 'char' [-Wchar-subscripts]
   59 |         cnt[ch]=i-1;
      |             ^~
password.cpp:74:64: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |             while(j<siz2 && query(rez+s2[j]+s1.substr(i,siz-i))==(rez+s2[j]+s1.substr(i,siz-i)).size())
      |                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
password.cpp:51:9: warning: variable 'cnt' set but not used [-Wunused-but-set-variable]
   51 |     int cnt[300]={0};
      |         ^~~
password.cpp: At global scope:
password.cpp:31:13: warning: 'void end(int)' defined but not used [-Wunused-function]
   31 | static void end(int success) {
      |             ^~~
password.cpp:28:18: warning: 'numQueries' defined but not used [-Wunused-variable]
   28 | static int n, s, numQueries;
      |                  ^~~~~~~~~~
password.cpp:28:15: warning: 's' defined but not used [-Wunused-variable]
   28 | static int n, s, numQueries;
      |               ^
password.cpp:28:12: warning: 'n' defined but not used [-Wunused-variable]
   28 | static int n, s, numQueries;
      |            ^
/usr/bin/ld: /tmp/cc3kUXg5.o: in function `query(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
grader.cpp:(.text+0x80): multiple definition of `query(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'; /tmp/ccOEcD97.o:password.cpp:(.text.unlikely+0x10): first defined here
collect2: error: ld returned 1 exit status