Posted on 2009-03-23 17:01
Hero 阅读(114)
评论(0) 编辑 收藏 引用 所属分类:
代码如诗--ACM
1 //1183 Accepted 0 136 882 C++ 特兰克斯
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <string.h>
5
6 int main()
7 {
8 char *pstra = new char[500] ;
9 char *pstrb = new char[500] ;
10 char *pstrc = new char[500] ;
11
12 while( scanf( "%s", pstra ) != EOF )
13 {
14 int lena = strlen( pstra ) ;
15 scanf( "%s", pstrb ) ; int lenb = strlen( pstrb ) ;
16 scanf( "%s", pstrc ) ; int lenc = strlen( pstrc ) ;
17
18 int cnt = 1 ;
19 char *posi = pstra ;
20 while( (posi=strstr(pstra, pstrb)) != NULL )
21 {
22 for( int i=1; i<=lenb; i++ )
23 {
24 *posi = cnt ; posi++ ;
25 }
26 if( 1 == cnt ) cnt = 2 ;
27 else cnt = 1 ;
28 }
29
30 cnt = 1 ;
31 for( int i=0; i<lena; )
32 {
33 if( pstra[i] == cnt )
34 {
35 printf( "%s", pstrc ) ;
36 while( pstra[i] == cnt ) i++ ;
37 if( 1 == cnt ) cnt = 2 ;
38 else cnt = 1 ;
39 }
40 else
41 {
42 printf( "%c", pstra[i++] ) ;
43 }
44 }
45 printf( "\n" ) ;
46 }
47 return 0 ;
48 }