9.9京东笔试

编程题一: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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值