답안 #1039384

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1039384 2024-07-30T19:35:33 Z ThommyDB Type Printer (IOI08_printer) C++17
10 / 100
29 ms 1884 KB
#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

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: suggest parentheses around assignment used as truth value [-Wparentheses]
   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('-');
      |                                 ~~^~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 432 KB Output is correct
2 Incorrect 0 ms 348 KB printed invalid word
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB printed invalid word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 440 KB printed invalid word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB printed invalid word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB printed invalid word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 604 KB printed invalid word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 840 KB printed invalid word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 29 ms 1856 KB printed invalid word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 22 ms 1884 KB printed invalid word
2 Halted 0 ms 0 KB -