Language: C++

#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
using namespace std;
#define vec vector
#define pb push_back
#define ins insert
int N;
vec<string> S;
set<char> T;
vec<int> dSet;

bool solve2() {
  map<char,int> m;
  int i=0;
  for(set<char>::iterator it = T.begin(); it!=T.end(); it++,i++) {
    m.ins(make_pair(*it,dSet[i]));
  }
  int left,buf;
  left=0;
  for(int i=0;i<S.size()-1;i++) {
    buf=0;
    for(int j=0;j<S[i].size();j++) {
      if(j==0 && S[i].size()>1 && m[S[i][j]] == 0) return false;
      buf = buf * 10 + m[S[i][j]];
    }
    left+=buf;
  }
  buf=0;
  for(int i=0;i<S[S.size()-1].size();i++) {
    if(i==0 && S[S.size()-1].size()>1 && m[S[S.size()-1][i]] == 0) return false;
    buf = buf * 10 + m[S[S.size()-1][i]];
  }
  return (left == buf);
}

int solve() {
  set<int> sInt;
  int ans=0;
  dSet.clear();
  for(int i=0;i<10;i++) dSet.pb(i);
  do {
    /*
    int left=0;
    for(int i=0;i<T.size();i++) {
      left = left * 10 + dSet[i];
    }
    if(sInt.count(left)) continue;
    else sInt.ins(left);
    */
    if(solve2()) ans++;
    //} while(next_permutation(dSet.begin(),dSet.end()));
  } while(next_permutation(dSet.begin(),dSet.begin()+T.size(),dSet.end()));
  return ans;
}

main() {
  while(cin>>N,N!=0) {
    S.clear(); T.clear();
    for(int i=0;i<N;i++) {
      string s; cin>>s;
      S.pb(s);
      for(int j=0;j<s.size();j++) T.ins(s[j]);
    }
    //printf("solving...\n");
    cout << solve() << endl;
    //printf("solve end\n");
  }
}

Compiler output:
a.cc:59:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   59 | main() {
      | ^~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:71,
                 from /usr/include/c++/14/string:51,
                 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/predefined_ops.h: In instantiation of 'constexpr bool __gnu_cxx::__ops::_Iter_comp_iter<_Compare>::operator()(_Iterator1, _Iterator2) [with _Iterator1 = __gnu_cxx::__normal_iterator<int*, std::vector<int> >; _Iterator2 = __gnu_cxx::__normal_iterator<int*, std::vector<int> >; _Compare = __gnu_cxx::__normal_iterator<int*, std::vector<int> >]':
/usr/include/c++/14/bits/stl_algo.h:2905:14:   required from 'bool std::__next_permutation(_BidirectionalIterator, _BidirectionalIterator, _Compare) [with _BidirectionalIterator = __gnu_cxx::__normal_iterator<int*, vector<int> >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<__gnu_cxx::__normal_iterator<int*, vector<int> > >]'
 2905 |           if (__comp(__i, __ii))
      |               ~~~~~~^~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:2985:2:   required from 'bool std::next_permutation(_BIter, _BIter, _Compare) [with _BIter = __gnu_cxx::__normal_iterator<int*, vector<int> >; _Compare = __gnu_cxx::__normal_iterator<int*, vector<int> >]'
 2984 |       return std::__next_permutation
      |              ~~~~~~~~~~~~~~~~~~~~~~~
 2985 |         (__first, __last, __gnu_cxx::__ops::__iter_comp_iter(__comp));
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:55:27:   required from here
   55 |   } while(next_permutation(dSet.begin(),dSet.begin()+T.size(),dSet.end()));
      |           ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/predefined_ops.h:158:30: error: no match for call to '(__gnu_cxx::__normal_iterator<int*, std::vector<int> >) (int&, int&)'
  158 |         { return bool(_M_comp(*__it1, *__it2)); }
      |                       ~~~~~~~^~~~~~~~~~~~~~~~