답안 #564469

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
564469 2022-05-19T09:30:40 Z MrDeboo 질문 (CEOI14_question_grader) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
int encode (int n, int x, int y) {
    if(x>n)x=0;
    if(y>n)y=0;
    string s;
    string f=to_string(x);
    while(f.size()<3)f="0"+f;
    s+=f;
    f=to_string(y);
    while(f.size()<3)f="0"+f;
    s+=f;
    return stoi(s);
}
#include <bits/stdc++.h>
int decode (int n, int q, int h) {
	string s=to_string(h);
	int a=0;
	for(int i=0;i<3;i++){
		a+=(h.back()-'0')*ceil(pow(10,i));
		h.pop_back();
	}
	int b=stoi(h);
	if(q==b)return 1;
	return 0;
}

Compilation message

encoder.cpp: In function 'int encode(int, int, int)':
encoder.cpp:5:5: error: 'string' was not declared in this scope
    5 |     string s;
      |     ^~~~~~
encoder.cpp:5:5: note: suggested alternatives:
In file included from /usr/include/c++/10/iosfwd:39,
                 from /usr/include/c++/10/ios:38,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from encoder.cpp:1:
/usr/include/c++/10/bits/stringfwd.h:79:33: note:   'std::string'
   79 |   typedef basic_string<char>    string;
      |                                 ^~~~~~
In file included from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from encoder.cpp:1:
/usr/include/c++/10/string:67:11: note:   'std::pmr::string'
   67 |     using string    = basic_string<char>;
      |           ^~~~~~
encoder.cpp:6:11: error: expected ';' before 'f'
    6 |     string f=to_string(x);
      |           ^~
      |           ;
encoder.cpp:7:11: error: 'f' was not declared in this scope
    7 |     while(f.size()<3)f="0"+f;
      |           ^
encoder.cpp:8:5: error: 's' was not declared in this scope
    8 |     s+=f;
      |     ^
encoder.cpp:8:8: error: 'f' was not declared in this scope
    8 |     s+=f;
      |        ^
encoder.cpp:9:7: error: 'to_string' was not declared in this scope; did you mean 'std::__cxx11::to_string'?
    9 |     f=to_string(y);
      |       ^~~~~~~~~
      |       std::__cxx11::to_string
In file included from /usr/include/c++/10/string:55,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from encoder.cpp:1:
/usr/include/c++/10/bits/basic_string.h:6666:3: note: 'std::__cxx11::to_string' declared here
 6666 |   to_string(long double __val)
      |   ^~~~~~~~~
encoder.cpp:12:12: error: 'stoi' was not declared in this scope; did you mean 'std::__cxx11::stoi'?
   12 |     return stoi(s);
      |            ^~~~
      |            std::__cxx11::stoi
In file included from /usr/include/c++/10/string:55,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from encoder.cpp:1:
/usr/include/c++/10/bits/basic_string.h:6677:3: note: 'std::__cxx11::stoi' declared here
 6677 |   stoi(const wstring& __str, size_t* __idx = 0, int __base = 10)
      |   ^~~~

decoder.cpp: In function 'int decode(int, int, int)':
decoder.cpp:3:2: error: 'string' was not declared in this scope
    3 |  string s=to_string(h);
      |  ^~~~~~
decoder.cpp:3:2: note: suggested alternatives:
In file included from /usr/include/c++/10/iosfwd:39,
                 from /usr/include/c++/10/ios:38,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from decoder.cpp:1:
/usr/include/c++/10/bits/stringfwd.h:79:33: note:   'std::string'
   79 |   typedef basic_string<char>    string;
      |                                 ^~~~~~
In file included from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from decoder.cpp:1:
/usr/include/c++/10/string:67:11: note:   'std::pmr::string'
   67 |     using string    = basic_string<char>;
      |           ^~~~~~
decoder.cpp:6:9: error: request for member 'back' in 'h', which is of non-class type 'int'
    6 |   a+=(h.back()-'0')*ceil(pow(10,i));
      |         ^~~~
decoder.cpp:7:5: error: request for member 'pop_back' in 'h', which is of non-class type 'int'
    7 |   h.pop_back();
      |     ^~~~~~~~
decoder.cpp:9:8: error: 'stoi' was not declared in this scope; did you mean 'std::__cxx11::stoi'?
    9 |  int b=stoi(h);
      |        ^~~~
      |        std::__cxx11::stoi
In file included from /usr/include/c++/10/string:55,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from decoder.cpp:1:
/usr/include/c++/10/bits/basic_string.h:6677:3: note: 'std::__cxx11::stoi' declared here
 6677 |   stoi(const wstring& __str, size_t* __idx = 0, int __base = 10)
      |   ^~~~