Submission #546863

# Submission time Handle Problem Language Result Execution time Memory
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()) {
      |                ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Expected integer, but "t" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Expected integer, but "e" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Expected integer, but "h" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 316 KB Expected integer, but "b" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Expected integer, but "a" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 340 KB Expected integer, but "a" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 596 KB Expected integer, but "a" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 988 KB Expected integer, but "a" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 28 ms 2032 KB Expected integer, but "a" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 28 ms 1960 KB Expected integer, but "a" found
2 Halted 0 ms 0 KB -