Submission #236384

# Submission time Handle Problem Language Result Execution time Memory
236384 2020-06-01T17:20:09 Z gurkot Type Printer (IOI08_printer) C++11
0 / 100
30 ms 896 KB
#include <iostream>
#include <algorithm>
using namespace std;

string S;
struct Word{ string s;};
bool operator <(Word a, Word b){
 int ka=0,kb=0;
 for (int i=0;i<a.s.size();i++)
  if (a.s[i]==S[i]) ka++; 
            else break;
 for (int i=0;i<b.s.size();i++)
  if (b.s[i]==S[i]) kb++; 
            else break;
 return ka<kb || ka==kb && a.s<b.s;
} 
Word word[2500];

int n,lmax,l;


main(){
 ios::sync_with_stdio(0);
 cin>>n;
 for (int i=0;i<n;i++) {
  cin>>word[i].s;
  l=word[i].s.size();
  if (lmax<l){
  	lmax=l; S=word[i].s;
  }
 }
  
 sort(word,word+n);
 
 int pos0=0;
 for (int i=0;i<word[0].s.size();i++) cout<<word[0].s[i]<<endl;
 cout<<"P"<<endl;
 
 for (int i=1;i<n;i++){
  int k=0;
  for (int j=0;j<min(word[i-1].s.size(),word[i].s.size());j++)
   if(word[i-1].s[j]==word[i].s[j]) k++; 
                             else break;
  l=word[i-1].s.size();
  for (int j=1;j<=l-k;j++) cout<<"-"<<endl;
  for (int j=k;j<word[i].s.size();j++) cout<<word[i].s[j]<<endl;
  cout<<"P"<<endl;
 }
}

/*
3
print
the
poem
*/

Compilation message

printer.cpp: In function 'bool operator<(Word, Word)':
printer.cpp:9:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i=0;i<a.s.size();i++)
               ~^~~~~~~~~~~
printer.cpp:12:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i=0;i<b.s.size();i++)
               ~^~~~~~~~~~~
printer.cpp:15:25: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
  return ka<kb || ka==kb && a.s<b.s;
                  ~~~~~~~^~~~~~~~~~
printer.cpp: At global scope:
printer.cpp:22:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
printer.cpp: In function 'int main()':
printer.cpp:36:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i=0;i<word[0].s.size();i++) cout<<word[0].s[i]<<endl;
               ~^~~~~~~~~~~~~~~~~
printer.cpp:41:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int j=0;j<min(word[i-1].s.size(),word[i].s.size());j++)
                ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:46:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int j=k;j<word[i].s.size();j++) cout<<word[i].s[j]<<endl;
                ~^~~~~~~~~~~~~~~~~
printer.cpp:35:6: warning: unused variable 'pos0' [-Wunused-variable]
  int pos0=0;
      ^~~~
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 384 KB Expected integer, but "t" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 384 KB Expected integer, but "e" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 384 KB Expected integer, but "h" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 384 KB Expected integer, but "b" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 384 KB Expected integer, but "a" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 30 ms 512 KB Expected integer, but "a" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 676 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 788 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 896 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -