Language: C++

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <cstring>
#include <map>

using namespace std;


typedef long long ll;
typedef pair<int,int> pii;
int N;
string strs[101];
char charSets[101];
int charKinds;
int charIds[1001];

int perm[101];
int nums[101];

int cnt;

void dfs(int pos,int idx){
    if(pos==charKinds){
        // SÔ·
        do{
            ll lSum=0;
            ll rSum=0;
            bool ok=true;
            for(int i=0;i<N;i++){
                ll mul=1;
                for(int j=strs[i].size()-1;j>=0;j--){
                    char ch=strs[i][j];
                    // æª¶É0ÌèÄÍsÂ\
                    if(j==0&&perm[charIds[ch]]==0&&strs[i].size()!=1){
                        ok=false;
                        break;
                    }
                    if(i!=N-1)lSum+=mul*perm[charIds[ch]];
                    else rSum+=mul*perm[charIds[ch]];
                    mul*=10;
                }
                if(!ok)break;
            }
            if(!ok)continue;
            if(lSum==rSum){
                cnt++;
            }
        }while(next_permutation(perm,perm+pos));
    }
    else{
        //idx©çiÌÔÅèÄ
        for(int i=idx;i<=9;i++){
            perm[pos]=i;
            dfs(pos+1,i+1);
        }
    }
}

int main(){
    bool used[1001];
    while(cin>>N&&N){
        charKinds=0;
        memset(used,0,sizeof(used));
        for(int i=0;i<N;i++){
            cin>>strs[i];
            for(int j=0;j<strs[i].size();j++){
                //charSets.insert(strs[i][j]);
                if(!used[strs[i][j]]){
                    used[strs[i][j]]=true;
                    charSets[charKinds++]=strs[i][j];
                    charIds[strs[i][j]]=charKinds-1;
                }
            }
        }
        cnt=0;
        dfs(0,0);
        cout<<cnt<<endl;
    }
    return 0;
}

Compiler output:
a.cc: In function 'void dfs(int, int)':
a.cc:41:54: error: 'ch' was not declared in this scope
   41 |                     if(i!=N-1)lSum+=mul*perm[charIds[ch]];
      |                                                      ^~
a.cc:42:49: error: 'ch' was not declared in this scope
   42 |                     else rSum+=mul*perm[charIds[ch]];
      |                                                 ^~
a.cc:47:15: error: expected 'while' before '(' token
   47 |             if(!ok)continue;
      |               ^
a.cc:47:17: error: 'ok' was not declared in this scope
   47 |             if(!ok)continue;
      |                 ^~
a.cc:47:20: error: expected ';' before 'continue'
   47 |             if(!ok)continue;
      |                    ^~~~~~~~
      |                    ;
a.cc:47:20: error: continue statement not within a loop
   47 |             if(!ok)continue;
      |                    ^~~~~~~~
a.cc:48:16: error: 'lSum' was not declared in this scope
   48 |             if(lSum==rSum){
      |                ^~~~
a.cc:48:22: error: 'rSum' was not declared in this scope
   48 |             if(lSum==rSum){
      |                      ^~~~
a.cc: At global scope:
a.cc:53:5: error: expected unqualified-id before 'else'
   53 |     else{
      |     ^~~~
a.cc:60:1: error: expected declaration before '}' token
   60 | }
      | ^