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 |
我也来一个In Reply To:我用string做的不知道厚道不厚道 Posted by:HIT_Happy at 2010-04-07 14:00:10 #include <iostream> using namespace std; int SafeStrcpy2KeyWord(char * pDestBuffer,char * pSourceString, int nDestBufferSize,char * szKeyWord) { if(strcmp(szKeyWord,"END")==0) { return -2; } if(strcmp(szKeyWord,"NULL")==0) { return -1; } int lenkw=strlen(szKeyWord); for(int i=0;i<nDestBufferSize-lenkw+1;i++) { if(strncmp(pSourceString+i,szKeyWord,lenkw)==0) { strncpy(pDestBuffer,pSourceString,i); pDestBuffer[i]='\0'; return i; } } strcpy(pDestBuffer,pSourceString); return nDestBufferSize; } int main() { //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); char pDestBuffer[260],pSourceString[260],szKeyWord[20]; while(scanf("%s",pSourceString)!=EOF) { int lens=strlen(pSourceString); while(true) { scanf("%s",szKeyWord); int lend=SafeStrcpy2KeyWord(pDestBuffer,pSourceString,lens,szKeyWord); if(lend==-1) { printf("0 NULL\n"); } else if(lend==-2) { break; } else if(lend==0) { printf("0 NULL\n"); } else { printf("%d %s\n",lend,pDestBuffer); } } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator