Submission #1039389

#TimeUsernameProblemLanguageResultExecution timeMemory
1039389ThommyDBType Printer (IOI08_printer)C++17
100 / 100
63 ms5572 KiB
#include<bits/stdc++.h> using namespace std; int n; vector<string> words; string largest_word, ans; bool compare(string x, string y){ int a = 0; for(int i = 0; i < x.size(); i++){ if(x[i]!=largest_word[i]){ a=i; break; } if(i==x.size()-1)a=x.size(); } int b = 0; for(int i = 0; i < y.size(); i++){ if(y[i]!=largest_word[i]){ b=i; break; } if(i==y.size()-1)b=y.size(); } return a==b ? x < y : a < b; } signed main(){ cin >> n; words.resize(n); for(int i = 0; i < n; i++){ cin >> words[i]; if(largest_word.size() < words[i].size()) largest_word = words[i]; } sort(words.begin(), words.end(), compare); ans = words[0] + 'P'; for(int i = 1; i < n; i++){ string& a = words[i-1]; string& b = words[i]; int hold; for(int j = 0; j < min(a.size(), b.size()); j++){ if(a[j]!=b[j]){ hold = j; break; } if(j == min(a.size(), b.size())-1) hold = min(a.size(), b.size()); } for(int j = a.size()-1; j >= hold; j--) ans.push_back('-'); for(int j = hold; j < b.size(); j++) ans.push_back(b[j]); ans.push_back('P'); } cout << ans.size() << "\n"; for(auto u : ans){ cout << u << "\n"; } }

Compilation message (stderr)

printer.cpp: In function 'bool compare(std::string, std::string)':
printer.cpp:11:22: 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 < x.size(); i++){
      |                    ~~^~~~~~~~~~
printer.cpp:16:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |         if(i==x.size()-1)a=x.size();
      |            ~^~~~~~~~~~~~
printer.cpp:19:22: 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 < y.size(); i++){
      |                    ~~^~~~~~~~~~
printer.cpp:24:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |         if(i==y.size()-1)b=y.size();
      |            ~^~~~~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:42:26: warning: comparison of integer expressions of different signedness: 'int' and 'const long unsigned int' [-Wsign-compare]
   42 |         for(int j = 0; j < min(a.size(), b.size()); j++){
      |                        ~~^~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:47:18: warning: comparison of integer expressions of different signedness: 'int' and 'long unsigned int' [-Wsign-compare]
   47 |             if(j == min(a.size(), b.size())-1) hold = min(a.size(), b.size());
      |                ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:50:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |         for(int j = hold; j < b.size(); j++) ans.push_back(b[j]);
      |                           ~~^~~~~~~~~~
printer.cpp:49:35: warning: 'hold' may be used uninitialized in this function [-Wmaybe-uninitialized]
   49 |         for(int j = a.size()-1; j >= hold; j--) ans.push_back('-');
      |                                 ~~^~~~~~~
#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...