无事可做,再做个简单的习题
Source Code
Problem: 3753 | User: lengshu | |
Memory: 156K | Time: 0MS | |
Language: C++ | Result: Accepted |
- Source Code
#include <stdio.h> #include <string> using namespace std; #define NULL_DEF 1 #define END_DEF 2 #define NORMAL_DEF 3 int SafeStrcpy2KeyWord(char* pDestBuffer, //拷贝的目的地地址 char* pSourceString, //拷贝的源地址 int nDestBufferSize, //拷贝的目的地缓冲区长度 char* szKeyWord) //指定关键字符串 { if (strcmp(szKeyWord,"NULL") == 0) return NULL_DEF; if (strcmp(szKeyWord,"END") == 0) return END_DEF; for (int i = 0; i <= nDestBufferSize - strlen(szKeyWord); i++) { if (strncmp(pSourceString + i,szKeyWord,strlen(szKeyWord)) == 0) { if (i == 0) return NULL_DEF; strncpy(pDestBuffer,pSourceString,i); pDestBuffer[i] = '/0'; return NORMAL_DEF; } } strcpy(pDestBuffer,pSourceString); return NORMAL_DEF; } int main(int argc, char* argv[]) { char pOriStr[260],pDest[260],pKey[20]; while(scanf("%s",pOriStr) != EOF) { while(1) { scanf("%s",pKey); int nT = SafeStrcpy2KeyWord(pDest,pOriStr,strlen(pOriStr),pKey); if (nT == NULL_DEF) printf("%d %s/n",0,"NULL"); else if (nT == END_DEF) break; else printf("%d %s/n",strlen(pDest),pDest); } } return 0; }