Click here to Skip to main content
15,884,836 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C++
#include<bits/std++.h>
#define ll long long int
#define ld long double
#define ite iterator
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define ioS ios::sync_with_stdio(false);
#define fr(i,x,n) for(int i=x;i<n;i++)>
#define re0 return 0 ;
#define mod 1000000007
using namespace std ;

ll  n,i,j,md,hi,lo ,mx,h,k,flag,sum,x,t,y,w,ans,q,hsh  ;
int main()
{
    cin >> t ;
    while(t--){
    string s;
    flag= 0 ;
    cin >> s;
     mx = 0;
   string::iterator itr1,itr2;

    for(itr1 = s.begin(); itr1 != s.end(); ++itr1)
        for( itr2 = itr1 + 1; itr2 != s.end(); ++itr2)
            mx = max(mx,(ll)(mismatch(itr1, itr1 + (s.end() - itr2), itr2).ff - itr1));
    if(flag==0)cout << mx << endl ;
    else cout << "0\n" ;
}
}
Posted
Updated 4-Oct-15 23:05pm
v6
Comments
Andreas Gieriet 4-Oct-15 13:56pm    
Where did you dig out this hair-raising code?
All these defines on top are crap, sorry.
Rewrite it first into decent C++ code before any attempt to translate into something else.
Regards
Andi
[no name] 5-Oct-15 12:25pm    
You wrote it, I thought it :)
Richard MacCutchan 5-Oct-15 7:00am    
Sorry, the answer is still no. This site does not provide a free code writing service.

1 solution

Basically, replace the cin >> with scanf, cout << with printf, and delete the namespace. The string will be an array of characters. and you will have to code the loops as "normal" for loops without the begin or end.

But to be honest, it probably doesn't do exactly what your tutor wants, and it won't be "good" c code anyway. You'll get a better grade if you ignore the place you found that and write your own... probably be easier in the long run as well...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900