답안 #1013666

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1013666 2024-07-03T19:07:22 Z Mardonbekhazratov Type Printer (IOI08_printer) C++17
30 / 100
21 ms 2412 KB
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

signed main(){
    int n;
    cin>>n;
    vector<string>a(n);
    int mx=0;
    char p;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i].size()>mx) p=a[i][0],mx=(int)a[i].size();
    }
    sort(a.begin(),a.end());
    vector<char>b;
    vector<char>ans;
    for(int i=0;i<n;i++){
        if(a[i][0]==p) continue;
        int j=0;
        while(j<b.size() && j<a[i].size() && a[i][j]==b[j]) j++;
        while(b.size()>j) ans.push_back('-'),b.pop_back();
        for(;j<a[i].size();j++) ans.push_back(a[i][j]),b.push_back(a[i][j]);
        ans.push_back('P');
    }
    for(int i=0;i<n;i++){
        if(a[i][0]!=p) continue;
        int j=0;
        while(j<b.size() && j<a[i].size() && a[i][j]==b[j]) j++;
        while(b.size()>j) ans.push_back('-'),b.pop_back();
        for(;j<a[i].size();j++) ans.push_back(a[i][j]),b.push_back(a[i][j]);
        ans.push_back('P');
    }
    cout<<(int)ans.size()<<'\n';
    for(char c:ans) cout<<c<<'\n';
}

Compilation message

printer.cpp: In function 'int main()':
printer.cpp:15:23: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   15 |         if(a[i].size()>mx) p=a[i][0],mx=(int)a[i].size();
      |            ~~~~~~~~~~~^~~
printer.cpp:23:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |         while(j<b.size() && j<a[i].size() && a[i][j]==b[j]) j++;
      |               ~^~~~~~~~~
printer.cpp:23:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |         while(j<b.size() && j<a[i].size() && a[i][j]==b[j]) j++;
      |                             ~^~~~~~~~~~~~
printer.cpp:24:23: warning: comparison of integer expressions of different signedness: 'std::vector<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   24 |         while(b.size()>j) ans.push_back('-'),b.pop_back();
      |               ~~~~~~~~^~
printer.cpp:25:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |         for(;j<a[i].size();j++) ans.push_back(a[i][j]),b.push_back(a[i][j]);
      |              ~^~~~~~~~~~~~
printer.cpp:31:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |         while(j<b.size() && j<a[i].size() && a[i][j]==b[j]) j++;
      |               ~^~~~~~~~~
printer.cpp:31:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |         while(j<b.size() && j<a[i].size() && a[i][j]==b[j]) j++;
      |                             ~^~~~~~~~~~~~
printer.cpp:32:23: warning: comparison of integer expressions of different signedness: 'std::vector<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   32 |         while(b.size()>j) ans.push_back('-'),b.pop_back();
      |               ~~~~~~~~^~
printer.cpp:33:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |         for(;j<a[i].size();j++) ans.push_back(a[i][j]),b.push_back(a[i][j]);
      |              ~^~~~~~~~~~~~
printer.cpp:29:9: warning: 'p' may be used uninitialized in this function [-Wmaybe-uninitialized]
   29 |         if(a[i][0]!=p) continue;
      |         ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 604 KB Output is correct
2 Incorrect 7 ms 1112 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 1336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 20 ms 2412 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 21 ms 2148 KB Output isn't correct
2 Halted 0 ms 0 KB -