uva 10361 Automatic Poetry

字符串处理,不过做的有点麻烦

View Code
 1 #include<stdio.h>
 2 #include<string.h>
 3 int main()
 4 {
 5     int n,i,j,k,x,len1,len2,count,y;
 6     char str1[1000],str2[1000],str[1000];
 7     scanf("%d",&n);
 8     getchar();
 9     while(n--)
10     {
11         gets(str1);
12         gets(str2);
13         len1=strlen(str1);
14         len2=strlen(str2);
15         count=0;
16         for(i=0;i<len1;i++)
17         {
18 
19             if(str1[i]!='<'&&str1[i]!='>')
20             {
21                 printf("%c",str1[i]);
22             }
23             else
24             {
25                 if(count==0&&str1[i]=='<')
26                 {
27                     y=i;
28                 }
29                 count++;
30             }
31         }
32         printf("\n");
33         k=0;
34         count=0;
35         for(i=len1-1;i>=0;)
36         {
37             if(str1[i]=='>')
38             {
39                 count++;
40                 if(count==1)
41                 x=i;
42                 while(str1[i]!='<')
43                 {
44                    i--;
45                 }
46 
47                 j=i+1;
48 
49                 while(str1[j]!='>')
50                 {
51                     str[k]=str1[j];
52                     k++;
53                     j++;
54                 }
55                 if(i>y)
56                 {
57                     while(str1[i]!='>')
58                     {
59                         i--;
60                     }
61                     j=i+1;
62                     while(str1[j]!='<')
63                     {
64                         str[k]=str1[j];
65                         k++;
66                         j++;
67                     }
68                 }
69                 else
70                 break;
71             }
72             else
73             i--;
74         }
75         for(x+=1;x<len1;x++)
76         {
77             str[k]=str1[x];
78             k++;
79         }
80         for(i=0;i<len2;)
81         {
82 
83             if(str2[i]=='.'&&str2[i+1]=='.'&&str2[i+2]=='.')
84             {
85                 for(j=0;j<k;j++)
86                 printf("%c",str[j]);
87                 i+=3;
88             }
89             else{
90             printf("%c",str2[i]);
91             i++;
92             }
93 
94         }
95         printf("\n");
96 
97     }
98     return 0;
99 }
原文地址:https://www.cnblogs.com/wanglin2011/p/2531447.html