Submission #656312

# Submission time Handle Problem Language Result Execution time Memory
656312 2022-11-06T23:26:27 Z Nakeeb Type Printer (IOI08_printer) C++17
0 / 100
44 ms 2800 KB
#include<bits/stdc++.h>
using namespace std;
string c;
bool cmp(string &a,string &b)
{
    int cnt1=a.size(),cnt2=b.size();
    for(int i=0;i<a.size();i++)
        if(a[i]!=c[i])
            cnt1=i;
    for(int i=0;i<b.size();i++)
        if(b[i]!=c[i])
            cnt2=i;
    if(cnt1==cnt2) return a<b;
    return cnt1<cnt2;
}
int main()
{
    int n;
    int mx=0;
    cin>>n;
    string s[n];
    for(int i=0;i<n;i++)
    {
        cin>>s[i];
        if(s[i].size()>mx||(s[i].size()==mx&&s[i]>c))
            mx=s[i].size(),c=s[i];
    }
    vector<char>ans;
    sort(s,s+n,cmp);
    for(int i=0;i<s[0].size();i++)
        ans.push_back(s[0][i]),ans.push_back('\n');
    ans.push_back('p'),ans.push_back('\n');
    for(int i=1;i<n;i++)
    {
        if(s[i-1].size()>s[i].size())
            for(int i=0;i<s[i-1].size()-s[i].size();i++)
                ans.push_back('-'),ans.push_back('\n');
        int sz=min(s[i-1].size(),s[i].size());
        int k=0;
        for(k;k<sz;k++)
            if(s[i-1][k]!=s[i][k])
                break;
        k--;
        for(int j=k;j<sz-1;j++)
            ans.push_back('-'),ans.push_back('\n');
        k++;
        for(;k<s[i].size();k++)
            ans.push_back(s[i][k]),ans.push_back('\n');
        ans.push_back('P'),ans.push_back('\n');
    }
    cout<<ans.size()/2<<endl;
    for(auto i:ans)
        cout<<i;
}

Compilation message

printer.cpp: In function 'bool cmp(std::string&, std::string&)':
printer.cpp:7:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    7 |     for(int i=0;i<a.size();i++)
      |                 ~^~~~~~~~~
printer.cpp:10:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |     for(int i=0;i<b.size();i++)
      |                 ~^~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:25:23: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   25 |         if(s[i].size()>mx||(s[i].size()==mx&&s[i]>c))
      |            ~~~~~~~~~~~^~~
printer.cpp:25:40: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   25 |         if(s[i].size()>mx||(s[i].size()==mx&&s[i]>c))
      |                             ~~~~~~~~~~~^~~~
printer.cpp:30:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |     for(int i=0;i<s[0].size();i++)
      |                 ~^~~~~~~~~~~~
printer.cpp:36:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |             for(int i=0;i<s[i-1].size()-s[i].size();i++)
      |                         ~^~~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:40:13: warning: statement has no effect [-Wunused-value]
   40 |         for(k;k<sz;k++)
      |             ^
printer.cpp:47:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |         for(;k<s[i].size();k++)
      |              ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB didn't print every word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB printed invalid word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB printed invalid word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 304 KB printed invalid word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB printed invalid word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 340 KB printed invalid word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 724 KB printed invalid word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 17 ms 1368 KB printed invalid word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 41 ms 2800 KB printed invalid word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 44 ms 2592 KB printed invalid word
2 Halted 0 ms 0 KB -