| Task: | Leimasin |
| Sender: | Ilmari2000 |
| Submission time: | 2018-10-05 22:41:16 +0300 |
| Language: | C++ |
| Status: | COMPILE ERROR |
Compiler report
input/code.cpp: In function 'int main()':
input/code.cpp:13:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(p < stamp.size() && stamp[p] == target[p])
~~^~~~~~~~~~~~~~
input/code.cpp:19:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(p < target.size())
~~^~~~~~~~~~~~~~~
input/code.cpp:22:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(lp1 < stamp.size() - 1 && stamp[lp1] != target[p])
~~~~^~~~~~~~~~~~~~~~~~
input/code.cpp:26:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(lp2 < stamp.size() && stamp[lp2] == target[p + lp2 - lp1])
~~~~^~~~~~~~~~~~~~
input/code.cpp:37:32: error: no matching function for call to 'std::__cxx11::basic_string<char>::basic_string(std::__cxx11::basic_string<char>::size_type, const char [2])'
string comp(target.size(), " ");...Code
#include <deque>
#include <iostream>
#include <string>
using namespace std;
int main()
{
string target, stamp;
cin >> target >> stamp;
int p = 0;
while(p < stamp.size() && stamp[p] == target[p])
p++;
deque<int> order;
order.push_back(0);
while(p < target.size())
{
int lp1 = 0;
while(lp1 < stamp.size() - 1 && stamp[lp1] != target[p])
lp1++;
int lp2 = lp1;
while(lp2 < stamp.size() && stamp[lp2] == target[p + lp2 - lp1])
lp2++;
if(lp1)
order.push_front(p - lp1);
else
order.push_back(p);
p += lp2 - lp1;
}
string comp(target.size(), " ");
for(int p : order)
{
for(int i = 0; i < stamp.size(); i++)
comp[p+i] = stamp[i];
}
if(comp != target)
{
cout << "-1" << endl;
return 0;
}
cout << order.size() << endl;
for(int p : order)
cout << p+1 << " ";
cout << endl;
}
