Language: C++

#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int n,d;
int a[10]={0,1,2,3,4,5,6,7,8,9};
char str[50][20];
void check();
int main(){
    int m,s;
    for(;;){
        cin>>n;
        if(n==0)exit(0);
        cin>>m>>s>>d;
        for(int i=1;i<=d;i++)cin>>str[i];
        check();
        if(a[s]==m)cout<<0<<endl;
        else {
            for(int i=1;i<=d;i++){
                for(int j=0;j<n-1;j++){
                    if((j==n-2&&str[i][j]!='1'&&str[i][j-1]!='1')||
                        (j==0&&str[i][j]!='1'&&str[i][j+1]!='1')||
                        (j!=0&&j!=n-2&&str[i][j]!='1'&&str[i][j+1]!='1'&&str[i][j-1]!='1')){
                        str[i][j]='1';
                        check();
                        if(a[s]==m){
                            cout<<i<<" "<<j+1<<endl;
                            goto end;
                        }
                        str[i][j]='0';
                        for(int k=0;k<10;k++)a[k]=k;
                    }
                }
            }
            cout<<1<<endl;
        }
        end:;
        for(int i=0;i<10;i++)a[i]=i;
        for(int i=0;i<50;i++)for(int j=0;j<20;j++)str[i][j]=0;
    }
    return 0;
}
void check(){
    for(int i=1;i<=d;i++){
        for(int j=1;j<n;j++){
            if(str[i][j-1]=='1')swap(a[j],a[j+1]);
        }
    }
    return;
}

            for(int i=1;i<=d;i++){
                for(int j=0;j<n-1;j++){
                    if((j==n-2&&str[i][j]!='1'&&str[i][j-1]!='1')||
                        (j==0&&str[i][j]!='1'&&str[i][j+1]!='1')||
                        (j!=0&&j!=n-2&&str[i][j]!='1'&&str[i][j+1]!='1'&&str[i][j-1]!='1')){
                        str[i][j]='1';
                        check();
                        if(a[s]==m){
                            cout<<i<<" "<<j+1<<endl;
                            goto end;
                        }
                        str[i][j]='0';
　　　　　　　　　　　　　for(int k=0;k<10;k++)a[k]=k;
                    }
                }
            }
            cout<<1<<endl;
        }
        end:;
        for(int i=0;i<10;i++)a[i]=i;
        for(int i=0;i<50;i++)for(int j=0;j<20;j++)str[i][j]=0;
    }
    return 0;
}
void check(){
    for(int i=1;i<=d;i++){
        for(int j=1;j<n;j++){
            if(str[i][j-1]=='1')swap(a[j],a[j+1]);
        }
    }
    return;
}

Compiler output:
a.cc:64:1: error: extended character 　 is not valid in an identifier
   64 | 　　　　　　　　　　　　　for(int k=0;k<10;k++)a[k]=k;
      | ^
a.cc:64:1: error: extended character 　 is not valid in an identifier
a.cc:64:1: error: extended character 　 is not valid in an identifier
a.cc:64:1: error: extended character 　 is not valid in an identifier
a.cc:64:1: error: extended character 　 is not valid in an identifier
a.cc:64:1: error: extended character 　 is not valid in an identifier
a.cc:64:1: error: extended character 　 is not valid in an identifier
a.cc:64:1: error: extended character 　 is not valid in an identifier
a.cc:64:1: error: extended character 　 is not valid in an identifier
a.cc:64:1: error: extended character 　 is not valid in an identifier
a.cc:64:1: error: extended character 　 is not valid in an identifier
a.cc:64:1: error: extended character 　 is not valid in an identifier
a.cc:64:1: error: extended character 　 is not valid in an identifier
a.cc:52:13: error: expected unqualified-id before 'for'
   52 |             for(int i=1;i<=d;i++){
      |             ^~~
a.cc:52:25: error: 'i' does not name a type
   52 |             for(int i=1;i<=d;i++){
      |                         ^
a.cc:52:30: error: 'i' does not name a type
   52 |             for(int i=1;i<=d;i++){
      |                              ^
a.cc:68:13: error: 'cout' does not name a type
   68 |             cout<<1<<endl;
      |             ^~~~
a.cc:69:9: error: expected declaration before '}' token
   69 |         }
      |         ^
a.cc:70:9: error: 'end' does not name a type
   70 |         end:;
      |         ^~~
a.cc:71:9: error: expected unqualified-id before 'for'
   71 |         for(int i=0;i<10;i++)a[i]=i;
      |         ^~~
a.cc:71:21: error: 'i' does not name a type
   71 |         for(int i=0;i<10;i++)a[i]=i;
      |                     ^
a.cc:71:26: error: 'i' does not name a type
   71 |         for(int i=0;i<10;i++)a[i]=i;
      |                          ^
a.cc:72:9: error: expected unqualified-id before 'for'
   72 |         for(int i=0;i<50;i++)for(int j=0;j<20;j++)str[i][j]=0;
      |         ^~~
a.cc:72:21: error: 'i' does not name a type
   72 |         for(int i=0;i<50;i++)for(int j=0;j<20;j++)str[i][j]=0;
      |                     ^
a.cc:72:26: error: 'i' does not name a type
   72 |         for(int i=0;i<50;i++)for(int j=0;j<20;j++)str[i][j]=0;
      |                          ^
a.cc:72:42: error: 'j' does not name a type
   72 |         for(int i=0;i<50;i++)for(int j=0;j<20;j++)str[i][j]=0;
      |                                          ^
a.cc:72:47: error: 'j' does not name a type
   72 |         for(int i=0;i<50;i++)for(int j=0;j<20;j++)str[i][j]=0;
      |                                               ^
a.cc:73:5: error: expected declaration before '}' token
   73 |     }
      |     ^
a.cc:74:5: error: expected unqualified-id before 'return'
   74 |     return 0;
      |     ^~~~~~
a.cc:75:1: error: expected declaration before '}' token
   75 | }
      | ^
a.cc:76:6: error: redefinition of 'void check()'
   76 | void check(){
      |      ^~~~~
a.cc:43:6: note: 'void check()' previously defined here
   43 | void check(){
      |      ^~~~~