这个代码会CE?

rt,原题:
P11705 「KTSC 2020 R1」字符串查找 - 洛谷
我的代码(写了注释是因为想写题解qwq):

#include <bits/stdc++.h>

using namespace std;

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

int main(void) 
{
	char T[1000005], P[1000005];
	cin >> T >> P;
	
	int N = strlen(T);
	int M = strlen(P);
	
	cout << findP(T, P, N, M);
	
	return 0;
}

int findP(char T[], char P[], int N, int M) {
	int cnt = 0;
	
	// 遍历T的每个子字符串
	for (int i = 0; i <= N - M; i++) {
		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;
}

这个代码在 IDE 模式里自测样例过了,咋会CE?求救qwq。

@2345安全卫士

@2345安全卫士 大佬救我qwq(

你确定c++版本没错?

1 个赞

C++17

编译信息

编译失败

No valid executable file was produced by the compiler /nix/store/p58l5qmzifl20qmjs3xfpl01f0mqlza2-binutils-2.40/bin/ld: ./ccqh5bDn.o: in function main': src:(.text.startup+0x0): multiple definition of main’; /tmp/compiler_z51z43qs/lib.o:src:(.text.startup+0x0): first defined here collect2: 错误:ld 返回 1

这个提高组蒟蒻连个语法题都写不出来了,难绷(

“编译器未生成有效的可执行文件”

1 个赞

这什么离谱报错,你重新提交试试?

1 个赞

交了9遍

甚至在线IDE也没报错

1 个赞

对的,

难绷(

要不用c++20试试?

1 个赞

试过了。。。报错都一样

???

1 个赞

发现问题了

1 个赞

这个报错显示你定义了多个main函数???

1 个赞

没有啊……代码就在上面

要不,试试把头文件改掉?

1 个赞

e

题目背景

请使用 C++17 或 C++20 提交本题

你需要在程序开头加入如下代码:

#include <bits/stdc++.h>

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

eee

1 个赞

我可以拿你的提交一下试试嘛

1 个赞