这个代码会CE?

破案了!!!111

ytx归来

1 个赞

是交互题!这个不会CE!

#include <bits/stdc++.h>

int findP(char T[], char P[], int N, int M);

int findP(char T[], char P[], int N, int M) {
	int cnt = 0;
	
	// 遍历T的每个子字符串
	for (int i = 0; i <= N - M; i++) {
		std::unordered_map<char, char> mt, mp;
		bool f = true;
		
		// 检查T[i...i+M-1]与P的映射关系
		for (int j = 0; j < M; j++) {
			char t = T[i + j];
			char p = P[j];
			
			// 如果T中的字符t已经映射过其他字符
			if (mt.count(t)) {
				if (mt[t] != p) {
					f = false;
					break;
				}
			} else {
				mt[t] = p;
			}
			
			// 如果P中的字符p已经映射过其他字符
			if (mp.count(p)) {
				if (mp[p] != t) {
					f = false;
					break;
				}
			} else {
				mp[p] = t;
			}
		}
		
		// 如果映射关系一致,增加计数
		if (f) {
			cnt++;
		}
	}
	
	return cnt;
}

咋了

2 个赞

@俞天行 为什么这样不会?

1 个赞

我也不知道……我看到是交互题,选了几题交互题的题解看看,发现不用写main,然后要加std::,不用using namespace std

1 个赞

o但是你的代码TLE了

1 个赞

hhh

2 个赞

还有你搞个基础段干嘛

2 个赞

水题(

3 个赞