Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
总是TLE,不解,求指点,附代码#include <stdio.h> #include <stdlib.h> #include <string.h> int SafeStrcpy2KeyWord(char* pDestBuffer, //拷贝的目的地地址 char* pSourceString, //拷贝的源地址 int nDestBufferSize, //拷贝的目的地缓冲区长度 char* szKeyWord) //指定关键字符串 { char *p; int len; if(NULL == szKeyWord) { strncpy(pDestBuffer, pSourceString, nDestBufferSize-1); pDestBuffer[nDestBufferSize-1] = '\0'; return strlen(pDestBuffer); } p = strstr(pSourceString, szKeyWord); if((NULL == p) || (pSourceString == p)) return 0; len = p - pSourceString; strncpy(pDestBuffer, pSourceString, len); pDestBuffer[len] = '\0'; return len; } int main(void) { char src_str[256]; char key_str[16]; char out_str[256]; char *p; int len; fgets(src_str, sizeof(src_str), stdin); while(strncmp(src_str, "EOF", 3)) { fgets(key_str, sizeof(key_str), stdin); while(strncmp(key_str, "END", 3)) { if(!strncmp(key_str, "NULL", 4)) { p = NULL; } else { p = key_str; key_str[strlen(key_str)-1] = '\0'; } len = SafeStrcpy2KeyWord(out_str, src_str, 256, p); if( 0 == len) printf("0 NULL\n"); else { printf("%d %s\n", len, out_str); } fgets(key_str, sizeof(key_str), stdin); } fgets(src_str, sizeof(src_str), stdin); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator