제출 #959207

#제출 시각아이디문제언어결과실행 시간메모리
959207maxFedorchukType Printer (IOI08_printer)C++17
100 / 100
111 ms5328 KiB
#include <bits/stdc++.h> using namespace std; string s=""; int in; bool cmp(string a,string b) { int in1=-1,in2=-1; for(int i=0;i<a.size();i++) { if(a[i]!=s[i]) { break; } in1=i; } for(int i=0;i<b.size();i++) { if(b[i]!=s[i]) { break; } in2=i; } if(in1==in2) { return (a<b); } return (in1<in2); } bool comp(string a,string b) { a=a.substr(0,b.size()); return (a==b); } int main() { cin.tie(0); ios_base::sync_with_stdio(0); int n; cin>>n; vector < string > mas; for(int i=1;i<=n;i++) { string a; cin>>a; mas.push_back(a); } sort(mas.begin(),mas.end()); for(int i=0;i<n;i++) { if(s.size()<mas[i].size()) { s=mas[i]; } } sort(mas.begin(),mas.end(),cmp); vector < char > ans; s=""; for(auto u:mas) { while(!comp(u,s)) { s=s.substr(0,s.size()-1); ans.push_back('-'); } for(int i=s.size();i<u.size();i++) { ans.push_back(u[i]); s+=u[i]; } ans.push_back('P'); } cout<<ans.size()<<"\n"; for(auto u:ans) { cout<<u<<"\n"; } return 0; }

컴파일 시 표준 에러 (stderr) 메시지

printer.cpp: In function 'bool cmp(std::string, std::string)':
printer.cpp:11:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |     for(int i=0;i<a.size();i++)
      |                 ~^~~~~~~~~
printer.cpp:19:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |     for(int i=0;i<b.size();i++)
      |                 ~^~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:81:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |         for(int i=s.size();i<u.size();i++)
      |                            ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...