Submission details
Task:Z-array
Sender:aalto26ih_022
Submission time:2026-11-02 15:44:04 +0200
Language:C++ (C++20)
Status:COMPILE ERROR

Compiler report

input/code.cpp:23:1: error: '::main' must return 'int'
   23 | void main()
      | ^~~~

Code

#include <iostream>
#include <vector>
#include <cmath>
#include <bits/stdc++.h>

using namespace std;

vector<int> z(string s) {
    int n = s.size();
    vector<int> z(n);
    int x = 0, y = 0;
    for (int i = 1; i < n; i++)
    {
        z[i] = max(0,min(z[i-x],y-i+1));
        while (i+z[i] < n && s[z[i]] == s[i+z[i]])
        {
            x = i; y = i+z[i]; z[i]++;
        }
    }
    return z;
}

void main()
{
    char temp;
    string s;
    while(cin >> temp)
    {
        s.push_back(temp);
    }
    vector<int> res = z(s);

    for(int val : res)
    {
        cout << val << " ";
    }
    cout << endl;
    
}