另類編輯距離 未通過程式碼
阿新 • • 發佈:2019-01-02
#include <iostream> #include <vector> #include <string> #include <algorithm> using namespace std; int main() { vector<char> vec1, vec2; vector <int> ans; string str1 = " "; string str2 = " "; char ch1; int result = 0; while (cin >> str1 >> str2) { vector<char> vec1, vec2; int hav = 0; for (size_t i = 0; i < str1.size(); i++) { ch1 = str1[i]; vec1.push_back(ch1); } for (size_t i = 0; i < str2.size(); i++) { ch1 = str2[i]; vec2.push_back(ch1); } for (vector<char>::iterator iter = vec1.begin(); iter != vec1.end(); iter++) { if (vec2.end() != std::find(vec2.begin(), vec2.end(), *iter)) { hav++; } } if (hav != 0) { if (vec1.size() > vec2.size()) { result = vec1.size() - hav; ans.push_back(result); } else { result = vec2.size() - hav; ans.push_back(result); } } else { result = vec1.size() + vec2.size(); ans.push_back(result); } } for (size_t i = 0; i < ans.size(); i++) cout << ans[i] << endl; return 0; }
不知道為什麼不能通過,線下測試時沒問題的。。。
不喜勿噴。