Submission #164261

#TimeUsernameProblemLanguageResultExecution timeMemory
164261kimbj0709Type Printer (IOI08_printer)C++17
100 / 100
171 ms5212 KiB
#include <bits/stdc++.h> using namespace std; #define int long long string longest; bool comp(string a,string b){ int lpa = 0,lpb = 0; for(int i=0;i<a.length();i++){ if(a.at(i)==longest.at(i)){ lpa++; } else{ break; } } for(int i=0;i<b.length();i++){ if(b.at(i)==longest.at(i)){ lpb++; } else{ break; } } if(lpa>lpb){ return 0; } else if(lpa<lpb){ return 1; } else{ return a<b; } } int32_t main() { string input; vector<string> vect1; int no_of_input; vector<char> ans; cin >> no_of_input; for(int i=0;i<no_of_input;i++){ cin >> input; vect1.push_back(input); if(input.length()>longest.length()){ longest = input; } } sort(vect1.begin(),vect1.end(),comp); string rn = ""; for(int i=0;i<vect1.size();i++){ string curr = vect1[i]; while(rn.length()>curr.length()){ ans.push_back('-'); rn.pop_back(); } for(int j=0;j<rn.length();j++){ if(rn.at(j)!=curr.at(j)){ for(int k=rn.length()-1;k>=j;k--){ ans.push_back('-'); rn.pop_back(); } goto cont; } } cont : ; for(int j=rn.length();j<curr.length();j++){ ans.push_back(curr.at(j)); rn += curr.at(j); } ans.push_back('P'); } cout << ans.size() << "\n"; for(auto k:ans){ cout << k << "\n"; } }

Compilation message (stderr)

printer.cpp: In function 'bool comp(std::__cxx11::string, std::__cxx11::string)':
printer.cpp:7:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0;i<a.length();i++){
               ~^~~~~~~~~~~
printer.cpp:15:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0;i<b.length();i++){
               ~^~~~~~~~~~~
printer.cpp: In function 'int32_t main()':
printer.cpp:49:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0;i<vect1.size();i++){
               ~^~~~~~~~~~~~~
printer.cpp:55:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int j=0;j<rn.length();j++){
                 ~^~~~~~~~~~~~
printer.cpp:65:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int j=rn.length();j<curr.length();j++){
                           ~^~~~~~~~~~~~~~
#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...