Language: C++

#include <cstdio>

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<n;i++)

using namespace std;

int k;

int dfs(vector<int> a, vector<int> b, int i){
    if(i == k-1) return (a[i] == b[i] ? 0LL : 1LL);

    int ret = INT_MAX, rotate = (b[i]-a[i]+10) % 10;
    vector<int> aa(a);
    aa[i] = b[i];
    reppp(j, i+1, k){
        ret = min(ret, dfs(aa, b, i+1));
        aa[j] = (a[j] + rotate) % 10;
    }
    ret = min(ret, dfs(aa, b, i+1));
    return ret + (a[i] == b[i] ? 0LL : 1LL);
}

int main(){
    while(scanf("%d", &k), k){
        string sa,sb;
        cin >> sa >> sb;
        vector<int> a(k), b(k);
        rep(k){
            a[i] = sa[i] - '0';
            b[i] = sb[i] - '0';
        }

        cout << dfs(a, b, 0) << endl;
    }
}


Compiler output:
a.cc:11:9: error: 'vector' was not declared in this scope
   11 | int dfs(vector<int> a, vector<int> b, int i){
      |         ^~~~~~
a.cc:2:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
    1 | #include <cstdio>
  +++ |+#include <vector>
    2 | 
a.cc:11:16: error: expected primary-expression before 'int'
   11 | int dfs(vector<int> a, vector<int> b, int i){
      |                ^~~
a.cc:11:24: error: 'vector' was not declared in this scope
   11 | int dfs(vector<int> a, vector<int> b, int i){
      |                        ^~~~~~
a.cc:11:24: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
a.cc:11:31: error: expected primary-expression before 'int'
   11 | int dfs(vector<int> a, vector<int> b, int i){
      |                               ^~~
a.cc:11:39: error: expected primary-expression before 'int'
   11 | int dfs(vector<int> a, vector<int> b, int i){
      |                                       ^~~
a.cc:11:44: error: expression list treated as compound expression in initializer [-fpermissive]
   11 | int dfs(vector<int> a, vector<int> b, int i){
      |                                            ^
a.cc: In function 'int main()':
a.cc:27:9: error: 'string' was not declared in this scope
   27 |         string sa,sb;
      |         ^~~~~~
a.cc:2:1: note: 'std::string' is defined in header '<string>'; this is probably fixable by adding '#include <string>'
    1 | #include <cstdio>
  +++ |+#include <string>
    2 | 
a.cc:28:9: error: 'cin' was not declared in this scope
   28 |         cin >> sa >> sb;
      |         ^~~
a.cc:2:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
    1 | #include <cstdio>
  +++ |+#include <iostream>
    2 | 
a.cc:28:16: error: 'sa' was not declared in this scope
   28 |         cin >> sa >> sb;
      |                ^~
a.cc:28:22: error: 'sb' was not declared in this scope
   28 |         cin >> sa >> sb;
      |                      ^~
a.cc:29:9: error: 'vector' was not declared in this scope
   29 |         vector<int> a(k), b(k);
      |         ^~~~~~
a.cc:29:9: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
a.cc:29:16: error: expected primary-expression before 'int'
   29 |         vector<int> a(k), b(k);
      |                ^~~
a.cc:31:13: error: 'a' was not declared in this scope
   31 |             a[i] = sa[i] - '0';
      |             ^
a.cc:32:13: error: 'b' was not declared in this scope
   32 |             b[i] = sb[i] - '0';
      |             ^
a.cc:35:9: error: 'cout' was not declared in this scope
   35 |         cout << dfs(a, b, 0) << endl;
      |         ^~~~
a.cc:35:9: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:35:21: error: 'a' was not declared in this scope
   35 |         cout << dfs(a, b, 0) << endl;
      |                     ^
a.cc:35:24: error: 'b' was not declared in this scope
   35 |         cout << dfs(a, b, 0) << endl;
      |                        ^
a.cc:35:20: error: 'dfs' cannot be used as a function
   35 |         cout << dfs(a, b, 0) << endl;
      |                 ~~~^~~~~~~~~
a.cc:35:33: error: 'endl' was not declared in this scope
   35 |         cout << dfs(a, b, 0) << endl;
      |                                 ^~~~
a.cc:2:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
    1 | #include <cstdio>
  +++ |+#include <ostream>
    2 |