답안 #236389

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
236389 2020-06-01T18:16:08 Z gurkot Type Printer (IOI08_printer) C++14
100 / 100
76 ms 3960 KB
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;

char S[21];
struct Word{ char s[21];};
bool operator <(Word a, Word b){
 int ka=0,kb=0;
 int la=strlen(a.s), lb=strlen(b.s);
 for (int i=0;i<la;i++)
  if (a.s[i]==S[i]) ka++; 
            else break;
 for (int i=0;i<lb;i++)
  if (b.s[i]==S[i]) kb++; 
            else break;
 return ka<kb || ka==kb && strcmp(a.s,b.s)<0;
} 
Word word[25001];

int n,lmax,l,lans;

char ans[1000001];

main(){
 
 scanf("%d",&n);
 for (int i=0;i<n;i++) {
  scanf("%s",word[i].s); l=strlen(word[i].s);  
  if (lmax<l){
  	lmax=l; strcpy(S,word[i].s);
  }
 }
  
 sort(word,word+n); 
 
 lans=0; 
 for (int i=0;i<strlen(word[0].s);i++) ans[lans++]=word[0].s[i];
 ans[lans++]='P';
 
 for (int i=1;i<n;i++){
  int k=0;
  for (int j=0;j<min(strlen(word[i-1].s),strlen(word[i].s));j++)
   if(word[i-1].s[j]==word[i].s[j]) k++; 
                             else break;
  l=strlen(word[i-1].s);
  for (int j=1;j<=l-k;j++) ans[lans++]='-';
  for (int j=k;j<strlen(word[i].s);j++) ans[lans++]=word[i].s[j];
  ans[lans++]='P';
 }
 
 printf("%d\n",lans);
 for (int i=0;i<lans;i++)
  printf("%c\n",ans[i]);
}

/*
3
print
the
poem
*/

Compilation message

printer.cpp: In function 'bool operator<(Word, Word)':
printer.cpp:17:25: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
  return ka<kb || ka==kb && strcmp(a.s,b.s)<0;
                  ~~~~~~~^~~~~~~~~~~~~~~~~~~~
printer.cpp: At global scope:
printer.cpp:25:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
printer.cpp: In function 'int main()':
printer.cpp:38:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i=0;i<strlen(word[0].s);i++) ans[lans++]=word[0].s[i];
               ~^~~~~~~~~~~~~~~~~~
printer.cpp:43:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int j=0;j<min(strlen(word[i-1].s),strlen(word[i].s));j++)
                ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:48:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int j=k;j<strlen(word[i].s);j++) ans[lans++]=word[i].s[j];
                ~^~~~~~~~~~~~~~~~~~
printer.cpp:27:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
  ~~~~~^~~~~~~~~
printer.cpp:29:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s",word[i].s); l=strlen(word[i].s);  
   ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 384 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 512 KB Output is correct
2 Correct 15 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 896 KB Output is correct
2 Correct 14 ms 896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 1664 KB Output is correct
2 Correct 65 ms 3448 KB Output is correct
3 Correct 43 ms 2424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 1656 KB Output is correct
2 Correct 76 ms 3960 KB Output is correct
3 Correct 50 ms 2680 KB Output is correct
4 Correct 71 ms 3832 KB Output is correct