¸øÒ»¸ö×Ö·û´®¡¢ÀýÈç ¡°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
Ïà¹ØÎÊ´ð£º
13¸öÈËΧ³ÉһȦ£¬´ÓµÚÒ»¸öÈË¿ªÊ¼Ë³Ðò±¨ºÅ1£¬2£¬3¡£·²±¨µ½3ÕßÍ˳öȦ×Ó£¬ÕÒ³ö×îºóÁôÔÚȦ×ÓÖеÄÈËÔÀ´µÄÐòºÅ
½á¹ûÓ¦¸ÃÊÇ13 ¿ÉÎҵijÌÐòµÄ½á¹ûÊÇ11 Ï£ÍûºÃÐÄÈ˰ï¸ÄÒ»ÏÂ
#include <stdio.h>
#include < ......
ÓÐÕâÑùÁ½¸öÎÊÌ⣬ϣÍû¸ßÊÖÖ¸µã£º
µÚÒ»£º
struct struct_A{
int a;
char b;
int c;
short d;
}
struct struct_B{
int a;
char b;
short c;
......
ÎÒÏÖÔÚÏ뽫ÕâËĸöÎļþ´Ó·þÎñÆ÷\\10.2.95.88\tempĿ¼ÏµÄËĸöÎı¾Îļþ£º1.txt ,2.txt ,3.txt , 4.txt´Ó·þÎñÆ÷ÏÂÔØµ½±¾µØ»úµÄC:\tempĿ¼Ï£¿
ÉÏÊöµÄ¹¦ÄÜÎÒÏëÓô¿CÓ¦¸ÃÈçºÎʵÏÖ£¿
ÓÃftpÐÒé¾Í¿ÉÒÔÁË
ÒýÓÃ ......
Ëã·¨Á÷³Ì
±¾Îĸù¾Ý¡¶ÖйúÒøÁªÖ±ÁªPOSÖն˹淶¡·µÄ²ûÊö£¬ÓÃCÓïÑÔ±à³ÌʵÏÖ£¬¸ÃËã·¨ÔÚʵ¼ÊµÄÉÌÒµPOSÖÕ¶ËÖÐʹÓá£POSÖն˲ÉÓãţãµļÓÃÜ·½Ê½£¬¼òÊöÈçÏ£º
a) ½«Óû·¢Ë͸øPOSÖÐÐĵÄÏûÏ¢ÖУ¬´ÓÏûÏ¢ÀàÐÍ£¨MTI£©µ½63Ó ......