大佬帮我看看代码哪出了问题
  • 板块灌水区
  • 楼主only_joker
  • 当前回复3
  • 已保存回复3
  • 发布时间2023/8/15 09:29
  • 上次更新2023/11/3 03:43:26
查看原帖
大佬帮我看看代码哪出了问题
719140
only_joker楼主2023/8/15 09:29
#include<bits/stdc++.h>
using namespace std;
const int MAXN=1e7;
string s;
int k,t=1,u=0,kkk=0;
bool f=true;
struct xd{
	string st;
	int n;
}a[MAXN];
int main(){
	cin>>s>>k;
	for(int i=k-1;i<s.size();i++)
	{
		if(i==k-1)
		{
			a[1].n=1;
			for(int j=0;j<k;j++)
			{
				a[1].st[j]=s[j];
			}
			continue;
		}
		string r;
		u=0;
		for(int j=i-k+1;j<=i;j++)
		{
			r[u]=s[j];
			u++;
		}
		for(int j=1;j<=t;j++)
		{
			if(r==a[j].st) 
			{
				a[j].n++;
				f=false;
				break;
			}
		}
		if(f==true)
		{
			t++;
			a[t].n=1;
			a[t].st=r;
		}
	}
	for(int i=1;i<=t;i++)
	{
		if(a[i].n>kkk) kkk=a[i].n;
	}
	cout<<kkk;
}

this

2023/8/15 09:29
加载中...