답안 #546863

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
546863 2022-04-08T17:06:34 Z ussef_abdallah Type Printer (IOI08_printer) C++14
0 / 100
28 ms 2032 KB
#include <bits/stdc++.h>

using namespace std;

int common(string &x, string &y) {
    int mn = min(x.length(), y.length());
    int cnt = 0;
    for (int i = 0; i < mn; i++) {
        if (x[i] == y[i])
            cnt++;
        else
            break;
    }
    return cnt;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector<string> a(n);
    string longest = "";
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        if (a[i].length() > longest.length())
            longest = a[i];
    }
    sort(a.begin(), a.end(), [&](string &x, string &y) {
        int commonX = common(x, longest);
        int commonY = common(y, longest);
        if (commonX == commonY)
            return x < y;
        return commonX < commonY;
    });
    string cur = "";
    int curPtr = 0;
    for (string &s : a) {
        int sPtr = 0;
        while (curPtr < cur.length() && sPtr < s.length()
               && cur[curPtr] == s[sPtr]) {

            curPtr++;
            sPtr++;
        }
        int toRemove = cur.length() - 1;
        while (toRemove >= curPtr) {
            cur.pop_back();
            toRemove--;
            cout << "-" << '\n';
        }
        while (sPtr < s.length()) {
            cout << s[sPtr] << "\n";
            cur += s[sPtr];
            sPtr++;
        }
        cout << "P" << '\n';
    }
    return 0;
}

Compilation message

printer.cpp: In function 'int main()':
printer.cpp:40:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |         while (curPtr < cur.length() && sPtr < s.length()
      |                ~~~~~~~^~~~~~~~~~~~~~
printer.cpp:40:46: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |         while (curPtr < cur.length() && sPtr < s.length()
      |                                         ~~~~~^~~~~~~~~~~~
printer.cpp:52:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |         while (sPtr < s.length()) {
      |                ~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Expected integer, but "t" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Expected integer, but "e" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Expected integer, but "h" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 316 KB Expected integer, but "b" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Expected integer, but "a" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 340 KB Expected integer, but "a" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 596 KB Expected integer, but "a" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 13 ms 988 KB Expected integer, but "a" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 28 ms 2032 KB Expected integer, but "a" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 28 ms 1960 KB Expected integer, but "a" found
2 Halted 0 ms 0 KB -