/images/avatar.png

^_^

字符串匹配算法(未完成)

从学习方法和代码实现debug花了挺长时间。。。

这个算法是从字符串s中找子串p出现的第一个位置

以下是两个常见的字符串匹配算法(还有其他更高效的比如Turbo-bm算法,sunday算法)

输入输出优化(提高读入输出速度)

参考https://blog.csdn.net/weixin_43960287/article/details/85337291

1.用scanf,printf代替cin,cout

2.取消同步和绑定

1
2
3
ios::sync_with_stdio(false);
cin.tie(0);
//cout.tie(0);

此时只能用cin,cout

3.对整型输入输出,将每个数字变成字符

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
inline int read()
{
	int x=0;int f=1;char s=getchar();
	while(s<'0' or  s>'9') 
	{
		if(s=='-')
			f-=1;
		s=getchar();
	}
	while(s>='0' and s<='9') 
	{
		x=x*10+s-'0';
		s=getchar();
	}
	return x*f;
}

void write(int x)
{
	if(x/10>0) write(x/10);
	putchar(char(x%10+'0'));
}

int main()
{
	//freopen("input.txt","r",stdin);
	int n=read();
	cout<<n<<endl;
	write(200);
	return 0;
} 


实验一 实验二 实验三 实验四 实验五 清空 例子