Language: C++

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

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

/*
返回模式串T在主串S中首次出现的位置
返回的位置是从0开始的。
*/
int KMP_Index()
{
    int i = 0, j = 0;
    int a, b;
    a = 0; 
    b = -1; 
  next[0] = -1;
    while(a < tlen){
        if(b == -1 || T[a] == T[b])
            next[++a] = ++b;
        else
            b = next[b];
    }
    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()
{
   while(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 'int KMP_Index()':
a.cc:21:3: error: reference to 'next' is ambiguous
   21 |   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 [55]'
    7 | int next[N];
      |     ^~~~
a.cc:24:13: error: reference to 'next' is ambiguous
   24 |             next[++a] = ++b;
      |             ^~~~
/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 [55]'
    7 | int next[N];
      |     ^~~~
a.cc:26:17: error: reference to 'next' is ambiguous
   26 |             b = next[b];
      |                 ^~~~
/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 [55]'
    7 | int next[N];
      |     ^~~~
a.cc:35:17: error: reference to 'next' is ambiguous
   35 |             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 [55]'
    7 | int next[N];
      |     ^~~~