답안 #236604

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
236604 2020-06-02T14:44:17 Z nickmet2004 Type Printer (IOI08_printer) C++11
0 / 100
18 ms 896 KB
#include<bits/stdc++.h>

using namespace std;

const int N = 25005;

int n;
int mx , P , cnt;
char MX[21];
char ans[1000005];

struct word{char s[21];}Words[N];
bool operator<(const word& A , const word& B){
    int prA = 0, prB = 0 , As = strlen(A.s) , Bs = strlen(B.s);
    for(int i = 0; i < As; ++i){
        if(A.s[i] != MX[i]) break; ++prA;
    }
    for(int i = 0; i < Bs; ++i){
        if(B.s[i] != MX[i]) break; ++prB;
    }
    return prA < prB || prA == prB && strcmp(A.s , B.s) < 0;
}

int main (){
    scanf("%d" , &n);
    for(int i = 0; i < n; ++i){
        scanf("%c" , Words[i].s);
        if(strlen(Words[i].s)> mx){mx = strlen(Words[i].s); strcpy(MX , Words[i].s);}
    }
    sort(Words , Words + n);
    cnt += strlen(Words[0].s);
    for(int k = 0; k < strlen(Words[0].s); ++k) {ans[P] = Words[0].s[k]; ++P;} ans[P] = 'P'; ++P;
    for(int i = 1; i < n; ++i){
        int pr = 0;
        for(int k = 0; k < min(strlen(Words[i].s) , strlen(Words[i - 1].s)); ++k){
            if(Words[i].s[k] != Words[i-1].s[k]) break; pr++;
        }
        cnt += strlen(Words[i-1].s) - pr; cnt += strlen(Words[i].s) - pr;
        for(int k = 1; k <= strlen(Words[i- 1].s) - pr; ++k){ans[P] = '-'; ++P;}
        for(int k = pr; k < strlen(Words[i].s); ++k){ans[P] = Words[i].s[k]; ++P;}
        ans[P] = 'P'; ++P;
    }
    printf("%d\n" , cnt + n);
    for(int i = 0; i < P; ++i) printf("%c\n" , ans[i]);
return 0;
}

Compilation message

printer.cpp: In function 'bool operator<(const word&, const word&)':
printer.cpp:16:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
         if(A.s[i] != MX[i]) break; ++prA;
         ^~
printer.cpp:16:36: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
         if(A.s[i] != MX[i]) break; ++prA;
                                    ^~
printer.cpp:19:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
         if(B.s[i] != MX[i]) break; ++prB;
         ^~
printer.cpp:19:36: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
         if(B.s[i] != MX[i]) break; ++prB;
                                    ^~
printer.cpp:21:36: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
     return prA < prB || prA == prB && strcmp(A.s , B.s) < 0;
                         ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:28:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(strlen(Words[i].s)> mx){mx = strlen(Words[i].s); strcpy(MX , Words[i].s);}
            ~~~~~~~~~~~~~~~~~~^~~~
printer.cpp:32:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int k = 0; k < strlen(Words[0].s); ++k) {ans[P] = Words[0].s[k]; ++P;} ans[P] = 'P'; ++P;
                    ~~^~~~~~~~~~~~~~~~~~~~
printer.cpp:35:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int k = 0; k < min(strlen(Words[i].s) , strlen(Words[i - 1].s)); ++k){
                        ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:36:13: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
             if(Words[i].s[k] != Words[i-1].s[k]) break; pr++;
             ^~
printer.cpp:36:57: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
             if(Words[i].s[k] != Words[i-1].s[k]) break; pr++;
                                                         ^~
printer.cpp:39:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int k = 1; k <= strlen(Words[i- 1].s) - pr; ++k){ans[P] = '-'; ++P;}
                        ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:40:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int k = pr; k < strlen(Words[i].s); ++k){ans[P] = Words[i].s[k]; ++P;}
                         ~~^~~~~~~~~~~~~~~~~~~~
printer.cpp:25:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d" , &n);
     ~~~~~^~~~~~~~~~~
printer.cpp:27:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%c" , Words[i].s);
         ~~~~~^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 384 KB Line "" doesn't correspond to pattern "[a-z\-P]{1}"
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 256 KB printed invalid word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 256 KB printed invalid word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 256 KB printed invalid word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 256 KB printed invalid word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 384 KB printed invalid word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 384 KB printed invalid word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 512 KB printed invalid word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 12 ms 768 KB printed invalid word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 18 ms 896 KB printed invalid word
2 Halted 0 ms 0 KB -