Submission #970451

# Submission time Handle Problem Language Result Execution time Memory
970451 2024-04-26T14:36:58 Z jadai007 Type Printer (IOI08_printer) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;

int n, dif, ans;
string s[25010];
string l;

int diff(string s1, string s2) {
    int i;
    for(i=0; i<min(s1.size(), s2.size()); i++) if(s1[i] != s2[i]) return i;
    return i;
}

bool cmp(string s1, string s2) {
    int diff1 = diff(s1, l);
    int diff2 = diff(s2, l);
    if(diff1 == diff2) return s1 < s2;
    return diff1 < diff2;
}

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    cin >> n;
    for(int i=1; i<=n; i++) {
        cin >> s[i];
        if(s[i].size() > l.size()) l = s[i];
    }
    sort(s+1, s+n+1, cmp);
    for(int i=1; i<=n; i++) {
        dif = diff(s[i-1], s[i]);
        ans += s[i-1].size() + s[i].size() - 2*dif;
    }
    cout << ans + n << "\n";
    for(int i=1; i<=n; i++) {
        dif = diff(s[i-1], s[i])ว
        for(int j=s[i-1].size(); j>dif; j--) cout << "-\n";
        for(int j=dif; j<s[i].size(); j++) cout << s[i][j] << "\n";
        cout << "P\n";
    }
}

Compilation message

printer.cpp: In function 'int diff(std::string, std::string)':
printer.cpp:11:15: warning: comparison of integer expressions of different signedness: 'int' and 'const long unsigned int' [-Wsign-compare]
   11 |     for(i=0; i<min(s1.size(), s2.size()); i++) if(s1[i] != s2[i]) return i;
      |              ~^~~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:36:33: error: expected ';' before '\U00000e27'
   36 |         dif = diff(s[i-1], s[i])ว
      |                                 ^
      |                                 ;
printer.cpp:37:34: error: 'j' was not declared in this scope
   37 |         for(int j=s[i-1].size(); j>dif; j--) cout << "-\n";
      |                                  ^
printer.cpp:38:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |         for(int j=dif; j<s[i].size(); j++) cout << s[i][j] << "\n";
      |                        ~^~~~~~~~~~~~