编程题一:AC 83%
#include <iostream>
#include <vector>
#include <numeric>
#include <limits>
#include<string>
#include<map>
using namespace std;
/*请完成下面这个函数,实现题目要求的功能
当然,你也可以不按照下面这个模板来作答,完全按照自己的想法来 ^-^
******************************开始写代码******************************/
class Solution {
public:
bool isIsomorphic(string s, string t) {
if (s.length() != t.length()) return false;
map<char, char> mp;
for (int i = 0; i < s.length(); i++) {
if (mp.count(s[i]) == 1 && mp[s[i]] != t[i])
return false;
else if (mp.count(s[i]) == 0) {
for (map<char, char>::iterator it = mp.begin(); it != mp.end(); it++) { if (it->second == t[i] && it->first != s[i]) return false; }
mp[s[i]] = t[i];
}
}
return true;
}
};
int solve(string S, string T) {
int num = 0;
int len_T = T.size();
Solution A;
for (int i = 0; i<=S.size()- len_T; ++i)
{
string temp = S.substr(i, len_T);
if (A.isIsomorphic(temp,T))
num++;
}
return num;
}
/******************************结束写代码******************************/
int main() {
int res;
string _S;
getline(cin, _S);
string _T;
getline(cin, _T);
res = solve(_S, _T);
cout << res << endl;
return 0;
}
bool Compare(string s, string t) {
if (s.length() != t.length()) return false;
map<char, char> mp;
for (int i = 0; i < s.length(); i++) {
if (mp.count(s[i]) == 1 && mp[s[i]] != t[i])
return false;
else if (mp.count(s[i]) == 0) {
for (map<char, char>::iterator it = mp.begin(); it != mp.end(); it++) { if (it->second == t[i] && it->first != s[i]) return false; }
mp[s[i]] = t[i];
}
}
return true;
}
1287

被折叠的 条评论
为什么被折叠?



