研发埠

标题: [google面试题]Write
 a
 program
 to 
determine
 whether
 an
 input 
string
 x 
is
 a 
substring 
of
 another
 input
 string
 y.

 [打印本页]

作者: 邓英超    时间: 2013-7-30 15:54
标题: [google面试题]Write
 a
 program
 to 
determine
 whether
 an
 input 
string
 x 
is
 a 
substring 
of
 another
 input
 string
 y.


(For example,"bat" is a substring of "abate",but not of "beat".) You may use any language you like.
作者: 亮    时间: 2013-7-30 16:41
Sample Answer(inC++):bool has Substring(const char *str, constchar *find) { if(str[0] == '\0' && find[0] == '\0') return true; for(int i = 0; str != '\0'; i++) { boolfoundNonMatch = false; for(int j = 0; find[j] != '\0'; j++) { if(str[i + j] != find[j]) { foundNonMatch = true; break; } } if(!foundNonMatch) return true; } return false;}




欢迎光临 研发埠 (http://bbs.yanfabu.com/) Powered by Discuz! X3.2