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 |
Re:哪位过的大神把代码贴出来瞧瞧。。。In Reply To:哪位过的大神把代码贴出来瞧瞧。。。 Posted by:0911180012 at 2010-01-16 12:21:38 > rt 记住一点就能AC, 当关键字找不到时, 输出整个字符串, 切记切记!!! #include<iostream> using namespace std; int main() { int i, j, keyLen, flag; char src[256], key[16]; while(scanf("%s", src) != EOF) { while(1) { flag = 1; scanf("%s", key); if(!strcmp(key, "END")) break; else if(!strcmp(key, "NULL")) { puts("0 NULL"); continue; } keyLen = strlen(key); for(i=0; i<=strlen(src) - keyLen; i++) { if(!strncmp(src + i, key, keyLen)) { if(i == 0) puts("0 NULL"); else { printf("%d ", i); for(j=0; j<i; j++) putchar(src[j]); printf("\n"); } flag = 0; break; } } if(flag) printf("%d %s\n", strlen(src), src); //puts("0 NULL"); } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator