UVA10115 - Automatic Editing

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=96&problem=1056&mosmsg=Submission+received+with+ID+10189080

纠结了 两天的一道题 由于字符串函数没用对 就一直做不对 搜了下解题报告 终于知道该怎么用了。

View Code
 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 #include<string.h>
 4 typedef struct node
 5 {
 6     char c1[100],c2[100];
 7 }st;
 8 int main()
 9 {
10     int n,t,i,j,k1,k2,m,g,f,y,flag,k;
11     char str[500],*ptr,d[500];
12     st a[50];
13     while(scanf("%d%*c",&t)&&t)
14     {
15         for(i = 1 ; i <= t ; i++)
16         {
17             gets(a[i].c1);
18             gets(a[i].c2);
19         }
20         gets(str);
21         for(i = 1 ; i <= t ; i++)
22         {
23             if(strstr(str,a[i].c1)!=NULL)
24             {
25                 ptr = strstr(str,a[i].c1) ;
26                 k = strlen(a[i].c1);
27                 strcpy(d,ptr+k);
28                 *ptr = '\0';
29                 strcat(str,a[i].c2);
30                 strcat(str,d);
31                 i--;
32             }
33         }
34         puts(str);
35     }
36     return 0;
37 }

 

posted @ 2012-06-04 19:28  _雨  阅读(183)  评论(0编辑  收藏  举报