Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

¹ØÓÚ×Ö·û´®µÄCÃæÊÔÌâ

¸øÒ»¸ö×Ö·û´®¡¢ÀýÈç ¡°ababc¡±ÒªÇ󷵻ء°ab¡±. ÒòΪ¡°ab¡±Á¬ÐøÖظ´³öÏÖÇÒ×¡£  ÓÃC/C£«£«ÓïÑÔдһº¯ÊýÍê³É¸ÃËã·¨£¬¸ø³ö¸´ÔÓ¶È
Õâ¸öÌâÎÒ²»»á

C/C++ code:

#include <iostream>
#include <string>

using namespace std;

bool getmaxsubstr(const string& s, string& oks);

int main()
{
string str;

while (cin >> str)
{
string s;
if (getmaxsubstr(str, s))
{
cout << s << endl;
}
else
{
cout << "do not exist!\n";
}
}

return 0;
}

bool getmaxsubstr(const string& s, string& oks)
{
string rets;
int len = 0;
bool bf = false;
for (int i = 0; i < s.size(); ++i)
{
for (int j = 1; j <= s.size() - i; ++j)
{
rets = s.substr(i, j);
if (s.find(rets, i + j) != string::npos && rets.size() > len)
{
len = rets.size();
oks = rets;
bf = true;
}
}
}

return bf;
}


O(n^2),ûÓп¼ÂÇsubstrÄÚ²¿µÄ¸´ÔÓ¶È¡£

ÎÊÌâÒªÇóÄÜ·ñÔÙÇåÎúһЩ

±ÈÈ磺"aababcabcd"µÄÇé¿öÏ£¬ab³öÏÖÁË3´Î£¬¶øabc³öÏÖÁË2´Î£¬Ó¦¸Ã·µ»ØÄÄÒ»¸ö£¿

#include <stdio.h>

#define BUF_MAX 1000


Ïà¹ØÎÊ´ð£º

СCµÄÎÊÌâ¹þ

C/C++ code:
#include <stdio.h>
typedef struct node{
int *key;
int length;
}node;
void insert(node &temp,int n)
{
int i,j;
for(i=0;i<=temp.length;i++)
{
......

cµÄ×Ö·û´®ÎÊÌâ

fastshow()
{
FILE *fp;
char name[10];
char ch[512];
printf("ÇëÊäÈë´ýÏÔʾµÄÎļþÃû\n");
scanf("%s",name);
if((fp=fopen(name,"r"))==NULL)
{
printf ......

CÎļþ¶ÁдÎÊÌâ¡£

FILE *pFile;
errno_t m_err;
m_err = fopen_s(&pFile,"1.txt","r");
char ch[100];
memset(ch,0,100);
fread(ch,1,100,pFile);
MessageBox(ch);
fclose(pFil ......

c ÓïÑÔ ¼ì²éÀ¨ºÅÆ¥Åä ²»ÄÜÔËÐÐ £¿£¿£¿£¿

¸÷λÇë°ïÎÒ¿´Ò»ÏÂÕâ¸ö¶«Î÷£¬ ÎÒÒªÔÚcÓïÑÔÖÐʵÏÖÀ¨ºÅÆ¥Å䣬Éè¼ÆË¼Â·£º°Ñ´ÓÁ´Õ»ÖÐɨÃèµÃµ½µÄ'}',¡®]',')'ÏÈ´æ´¢µ½¶¯Ì¬ÉêÇëµÄÄÚ´æ¿Õ¼äÖУ¬µ±É¨Ãèµ½¡®{','[','('ʱ ÔÚµ¯³öÏÈǰ´ ......

ѧϰÌÖÂÛ C/C++ QQȺ - C/C++ / ·Ç¼¼ÊõÇø

QQȺ 29152388
ÓÑÇéUP

°ï¶¥

up

°ïup

up Ö§³Ö£¡

up jf

...ÄѵÀÓзÖ..?

up up up
Ï£ÍûÓеüӷ֣¬¹þ¹þ¡£

Ö§³Ö£¬ÎÒ¼ÓÁË£¬Ï£ÍûÂ¥Ö÷ÄܼÓÎÒ£¬¹²Í¬Ñ§Ï°¹þ

¼ÓÁË¡£

¶¥ÉÏ£¬Ã¿ÌìÊÕ»ñÒ»µã£¬Ö§³Ö ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ