1 条题解

  • 0
    @ 2025-10-10 19:43:51

    C++ :

    #include <bits/stdc++.h>
    using namespace std;
    
    int main()
    {
    	string a,b,c;
    	int vis[100]={0},len,i,j,l,maxx=0,cnt,id;
    	cin>>a;
    	len=a.length();
    	b=a[0];
    	cnt=0;
    	i=1;
    	j=1;
    	while(j<len)
    	{
    		if(a.find(b,i)!=string::npos)
    		{
    			cnt++;
    			if(maxx<cnt)
    			{
    				id=j;
    				maxx=cnt;
    				c=b;
    			}
    			b+=a[i];
    			i++;	
    		}
    		else
    		{
    			b=a[j++];
    			cnt=0;
    			i=j;
    		}
    	}
    	cout<<c<<endl;
    	cout<<id<<endl;
    return 0;
    }
    

    Pascal :

    var
    s:string;
    a:array[1..100]of string;
    i,j,t,m,h,k:integer;
    begin
     readln(s);
     t:=length(s);
     for i:=1 to t-1 do
     begin
      m:=i+1;
      for j:=1 to m do a[j]:=copy(s,j,t-i);
      for h:=1 to m do
      for k:=1 to m do
      if (a[h]=a[k])and(h<>k) then begin writeln(a[k]);writeln(h);exit;end;
     end;
    end.
    
    • 1

    信息

    ID
    935
    时间
    1000ms
    内存
    512MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者