HDU Automatic Correction of Misspellings (复杂模拟题)
来源:互联网 发布:一知f君百度网盘郑子豪 编辑:程序博客网 时间:2024/05/04 00:55
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1483
复杂模拟,在开始做之前一定要清晰的在草纸上写出模拟的思路和各个模块!!
锻炼代码能力!
另外发现了一个问题:s.length()-len < 0 时直接得出的结果非负数 会很大
例如下面
我们看到结果很大,这样就说明是错误的,我们可以先把s1.length()的值给另一个变量,然后再做减法,这样结果就对了
还有记得用s.erase(dex, amount);的时候注意s.length是变化的.
AC代码:
#include <bits/stdc++.h>using namespace std;typedef pair<int, int> P;typedef long long LL;#define INF 0x3f3f3f3f#define PI acos(-1)#define MAX_N 10005//#define LOCALset<string> st;string dic[MAX_N];int N;int solve(string now){ int ret = INF; int len = now.length(); for(int i = 0; i < N; i++) { string tdic = dic[i]; int len2 = tdic.length(); //注意 不可以用 dic[i].length()-now.length(); 此处注意.length()是长整形,不知道为何数据很大 if(abs(len2-len) > 1) //长度过长或过短 { continue; } if(tdic.length() == len) //长度相等的时候2,3的情况 { vector<int> dex; int cnt = 0; for(int j = 0; j < len; j++) { if(tdic[j] != now[j]) { cnt++; dex.push_back(j); } if(cnt > 2) break; } if(cnt == 1) //第二种情况 { return i; } else if(cnt == 2) //第三种情况 { int fir = dex[0], sec = dex[1]; if(tdic[fir] == now[sec] && tdic[sec] == now[fir]) { return i; } } dex.clear(); } else { string chang, duan; if(tdic.length() > len) { chang = tdic; duan = now; } else { chang = now; duan = tdic; } for(int j = 0; j < chang.length(); j++) { if(chang[j] != duan[j]) { chang.erase(j,1); break; } } if(chang.length() != duan.length()) continue; bool have = 0; for(int j = 0; j < duan.length(); j++) { if(chang[j] != duan[j]) { have = 1; break; } } if(!have) return i; } } return ret;}int main(){#ifdef LOCALfreopen("b:\\data.in.txt", "r", stdin);#endif scanf("%d", &N); for(int i = 0; i < N; i++) { cin >> dic[i]; st.insert(dic[i]); } int q; scanf("%d", &q); string que_s; set<string>::iterator it;// for(it=st.begin(); it!=st.end(); it++)// {// cout << *it << "-- " << endl;// } for(int i = 0; i < q; i++) { cin >> que_s; if(st.find(que_s) != st.end()) { cout << que_s << " is correct" << endl; } else { int ret = solve(que_s); if(ret != INF) { cout << que_s << " is a misspelling of " << dic[ret] << endl; } else cout << que_s << " is unknown" << endl; } } return 0;}
0 0
- HDU Automatic Correction of Misspellings (复杂模拟题)
- HDU 1483 Automatic Correction of Misspellings (字符串大模拟)
- Automatic Correction of Misspellings
- HDU 6023 Automatic Judge (模拟)
- (HDU 6023 女生专场)Automatic Judge 简单模拟
- hdu 5938 Four Operations(复杂的模拟题)
- POJ 2260 Error Correction 模拟题
- UVA Automatic Poetry(模拟)
- correction of ar_pose compilation
- hdu-Error Correction
- HDU Error Correction
- HDU-#5018 Revenge of Fibonacci(模拟)
- HDU-#4432 Sum of divisors(模拟)
- hdu 4432 Sum of divisors(模拟)
- HDU 6144 Arithmetic of Bomb(模拟)
- POJ 2260 Error Correction(模拟)
- POJ 2260 Error Correction (模拟)
- POJ-2260 Error Correction 模拟
- 编译编写简易ipk程序
- openwrt +Eclipse开发环境+调试
- 【NOI2005】【JZOJ 2413】【BZOJ 1500】维护数列
- 嵌入百度UEditor到JAVA+MAVEN+SpringMVC项目中
- android:padding和android:layout_margin的区别
- HDU Automatic Correction of Misspellings (复杂模拟题)
- ROS中rosrun和roslaunch命令的对比
- 如何划分程序员的技术层级
- 网址
- ubuntu16.04修改网卡名称enp2s0为eth0
- yii框架中xphinx搜索
- 蓝桥网 算法训练 幂方分解
- android图片压缩
- leetcode263: Ugly Number