Language: C++

#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;

const int N = 1000002;
int next[N];
char S[N], T[N];
int slen, tlen;

void getNext()
{
    int j, k;
    j = 0; k = -1; next[0] = -1;
    while(j < tlen)
        if(k == -1 || T[j] == T[k])
            next[++j] = ++k;
        else
            k = next[k];

}
/*
返回模式串T在主串S中首次出现的位置
返回的位置是从0开始的。
*/
int KMP_Index()
{
    int i = 0, j = 0;
    getNext();

    while(i < slen && j < tlen)
    {
        if(j == -1 || ((S[i] == T[j])||(S[i]=='?')))
        {
            i++; j++;
        }
        else
            j = next[j];
    }
    if(j == tlen)
        return i - tlen;
    else
        return -1;
}
/*
返回模式串在主串S中出现的次数
*/

int main()
{

    int TT;
    int i, cc;
        cin>>S>>T;
        slen = strlen(S);
        tlen = strlen(T);
        int len=KMP_Index();
        if(len!=-1)
        {
            for(int i=0,j=0;i<slen;i++)
            {
                if(S[i]=='?'&&i<len)
                    printf("%c",'a');
                else if(i>=len&&i<=len+tlen)
                    {
                        printf("%c",T[j++]);
                    }
                else if(S[i]!='?')
                    printf("%c",S[i]);
            }
            printf("\n");
        }
        else
        printf("UNRESTORABLE\n");

    return 0;
}


Compiler output:
a.cc: In function 'void getNext()':
a.cc:14:20: error: reference to 'next' is ambiguous
   14 |     j = 0; k = -1; next[0] = -1;
      |                    ^~~~
In file included from /usr/include/c++/14/string:47,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:7:5: note:                 'int next [1000002]'
    7 | int next[N];
      |     ^~~~
a.cc:17:13: error: reference to 'next' is ambiguous
   17 |             next[++j] = ++k;
      |             ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:7:5: note:                 'int next [1000002]'
    7 | int next[N];
      |     ^~~~
a.cc:19:17: error: reference to 'next' is ambiguous
   19 |             k = next[k];
      |                 ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:7:5: note:                 'int next [1000002]'
    7 | int next[N];
      |     ^~~~
a.cc: In function 'int KMP_Index()':
a.cc:38:17: error: reference to 'next' is ambiguous
   38 |             j = next[j];
      |                 ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:7:5: note:                 'int next [1000002]'
    7 | int next[N];
      |     ^~~~