提交时间:2024-01-07 14:08:21
运行 ID: 229939
#include <bits/stdc++.h> using namespace std; int n; string a; string b; bool c[1005] = {0}; int sum = 0; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n; cin >> a >> b; for(int i = 0;i < n;i++) { if(a[i] == b[i]) { c[i] = 1; sum++; } } int mx = 0; int mxx = -0x7f7f7f7f; for(int i = 0;i < n - 1;i++) { for(int j = i+1;j < n;j++) { mx = 0; if(b[i] == a[j] && !c[j]) { mx++; } if(b[j] == a[i] && !c[i]) { mx++; } mxx = max(mx,mxx); if(mxx == 2) { break; } } } cout << sum + mxx << endl; return 0; }