1 solutions
-
0
C++ :
#include<iostream> #include<cstring> #include<algorithm> using namespace std; int main() { string s1,s[11000],s2,s3[11000],s4[11000]; int wei=-1,a=0,b=0,t=0,h,w=-1; cin>>s1; int len=s1.size(); for(int i=0;i<=len-1;i++) for(int j=1;j<=len-i;j++) { s2=s1.substr(i,j); wei=s1.find(s2,j+i); if(wei!=-1) { s[a]=s2; a++; } else continue; } for(int i=0;i<=a-1;i++) { h=s[i].size(); if(h>=t) { t=h; s3[b]=s[i]; b++; } } for(int i=0;i<=b-1;i++) if(s3[i].size()==t) { w++; s4[w]=s3[i]; } sort(s4+0,s4+w+1,less<string>()); s2=s4[0]; cout<<s2<<endl; cout<<s1.find(s2,0)<<endl; }
- 1
Information
- ID
- 17937
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By