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 |
到底是怎么回事??n个wa。。#include <stdio.h> #include <stdlib.h> int SafeStrcpy2KeyWord(char* pDestBuffer, //源字符串 char* pSourceString, //目的字符串 int nDestBufferSize, //缓冲区长度 char* szKeyWord //指定键字符串 ) { char buf[nDestBufferSize]; int index = -1, i, j; for(i=0; pDestBuffer[i]!=0&&i<nDestBufferSize; i++) { if(pDestBuffer[i]==szKeyWord[0]) { for(j=1; szKeyWord[j]!=0&&pDestBuffer[i+j]!=0&&i+j<nDestBufferSize; j++) { if(pDestBuffer[i+j]!=szKeyWord[j]) break; } if(szKeyWord[j]==0) { index = i; break; } } } if(index==0) { pSourceString[0] = 0; return index; } if(index==-1) { for(i=0; i<pDestBuffer[i]!=0&&i<nDestBufferSize; i++) { pSourceString[i] = pDestBuffer[i]; } if(pDestBuffer[i]!=0) return 0; pSourceString[i] = 0; return i; } for(i=0; i<index; i++) { pSourceString[i] = pDestBuffer[i]; } pSourceString[index] = 0; return index; } void getline(char str[], int limit) { char c; int i; i=0; scanf("%c", &c); while(c!='\n'&&i<limit) { str[i++] = c; scanf("%c", &c); } str[i] = 0; } int main() { char sourceString[300], newString[300]; char key[30]; int len; while(scanf("%s", &sourceString)!=EOF) { getline(key, 30); while(1) { getline(key, 30); if(key[0]=='E'&&key[1]=='N'&&key[2]=='D'&&key[3]==0) { break; } if(key[0]=='N'&&key[1]=='U'&&key[2]=='L'&&key[3]=='L'&&key[4]==0) { printf("0 NULL\n"); continue; } len = SafeStrcpy2KeyWord(sourceString, newString, 300, key); if(len==0) printf("0 NULL\n"); else printf("%d %s\n", len, newString); } } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator