字符串处理 Codeforces Round #296 (Div. 2) B. Error Correct System
2015-03-25 20:11
471 查看
题目传送门
/* 无算法 三种可能:1.交换一对后正好都相同,此时-2 2.上面的情况不可能,交换一对后只有一个相同,此时-1 3.以上都不符合,则不交换,-1 -1 */ #include <cstdio> #include <iostream> #include <algorithm> #include <cmath> #include <cstring> #include <string> #include <map> #include <set> #include <vector> #include <set> using namespace std; const int MAXN = 2e5 + 10; const int INF = 0x3f3f3f3f; char s[MAXN], t[MAXN]; int p[30][30]; bool check1(int cnt) { for (int i=0; i<26; ++i) { for (int j=0; j<26; ++j) { if (p[i][j] && p[j][i]) { printf ("%d\n", cnt-2); printf ("%d %d\n", p[i][j], p[j][i]); return true; } } } return false; } bool check2(int cnt) { for (int i=0; i<26; ++i) { for (int j=0; j<26; ++j) { if (p[i][j]) { for (int k=0; k<26; ++k) { if (p[k][i]) { printf ("%d\n", cnt-1); printf ("%d %d\n", p[i][j], p[k][i]); return true; } } } } } return false; } void work(int n) { int cnt = 0; for (int i=0; i<n; ++i) { if (s[i] != t[i]) { p[s[i]-'a'][t[i]-'a'] = i + 1; cnt++; } } if (check1 (cnt)) return ; if (check2 (cnt)) return ; printf ("%d\n", cnt); puts ("-1 -1"); } int main(void) { //freopen ("B.in", "r", stdin); int n; while (~scanf ("%d", &n)) { memset (p, 0, sizeof (p)); scanf ("%s", &s); scanf ("%s", &t); work (n); } return 0; }
相关文章推荐
- Codeforces Round #296 (Div. 2) - B. Error Correct System(脑洞)
- Codeforces Round #296 (Div. 2) B. Error Correct System
- B. Error Correct System (CF Round #296 (Div. 2))
- Codeforces Round #296 (Div. 2)——B——Error Correct System
- Codeforces Round #296 (Div. 2) B. Error Correct System
- B. Error Correct System (CF Round #296 (Div. 2))
- Codeforces Round #296 (Div. 2) B. Error Correct System
- Codeforces Round #324 (Div. 2) C. Marina and Vasya 字符串处理
- Codeforces Round #FF (Div. 2/B)/Codeforces447B_ DZY Loves Strings(字符串处理)
- Codeforces Round #256 (Div. 2/B)/Codeforces448B_Suffix Structures(字符串处理)
- Codeforces Round #389 (Div. 2) B. Santa Claus 贪心+字符串处理、易错
- system单元的几个字符串处理方法
- mono touch通过引用System.Json.dll处理url请求,转成json字符串
- Codeforces Round #373 (Div. 2) C. Efim and Strange Grade 贪心、实数字符串"a.b"处理
- uva:310 - L--system(字符串处理+ bfs)
- 关于“System.Data.SqlClient.SqlError:媒体集有2个媒体簇,但只提供了1个。必须提供所有成员”处理与
- CF_527B_ErrorCorrectSystem
- Codeforces Round #186 (Div. 2) / 313B Ilya and Queries (字符串处理)
- Error loading opeating system 加载系统错误处理方法
- SpringMVC3中返回json字符串时500 Internal Server Error的处理方案