题目传送门
1 /*
2 无算法
3 三种可能:1.交换一对后正好都相同,此时-2
4 2.上面的情况不可能,交换一对后只有一个相同,此时-1
5 3.以上都不符合,则不交换,-1 -1
6
7 */
8 #include <cstdio>
9 #include <iostream>
10 #include <algorithm>
11 #include <cmath>
12 #include <cstring>
13 #include <string>
14 #include <map>
15 #include <set>
16 #include <vector>
17 #include <set>
18 using namespace std;
19
20 const int MAXN = 2e5 + 10;
21 const int INF = 0x3f3f3f3f;
22
23 char s[MAXN], t[MAXN];
24 int p[30][30];
25
26 bool check1(int cnt)
27 {
28 for (int i=0; i<26; ++i)
29 {
30 for (int j=0; j<26; ++j)
31 {
32 if (p[i][j] && p[j][i])
33 {
34 printf ("%d
", cnt-2);
35 printf ("%d %d
", p[i][j], p[j][i]);
36 return true;
37 }
38 }
39 }
40
41 return false;
42 }
43
44 bool check2(int cnt)
45 {
46 for (int i=0; i<26; ++i)
47 {
48 for (int j=0; j<26; ++j)
49 {
50 if (p[i][j])
51 {
52 for (int k=0; k<26; ++k)
53 {
54 if (p[k][i])
55 {
56 printf ("%d
", cnt-1);
57 printf ("%d %d
", p[i][j], p[k][i]);
58 return true;
59 }
60 }
61 }
62 }
63 }
64
65 return false;
66 }
67
68 void work(int n)
69 {
70 int cnt = 0;
71 for (int i=0; i<n; ++i)
72 {
73 if (s[i] != t[i])
74 {
75 p[s[i]-'a'][t[i]-'a'] = i + 1;
76 cnt++;
77 }
78 }
79 if (check1 (cnt)) return ;
80 if (check2 (cnt)) return ;
81
82 printf ("%d
", cnt);
83 puts ("-1 -1");
84 }
85
86 int main(void)
87 {
88 //freopen ("B.in", "r", stdin);
89
90 int n;
91 while (~scanf ("%d", &n))
92 {
93 memset (p, 0, sizeof (p));
94 scanf ("%s", &s);
95 scanf ("%s", &t);
96
97 work (n);
98 }
99
100 return 0;
101 }