C程序设计语言-练习2-4

题目:将字符串s1中任何与字符串s2中字符相匹配的字符都删除

 1 #include <cstdio>
 2 
 3 using namespace std;
 4 
 5 //将字符串s1中任何与字符串s2中字符匹配的字符都删除
 6 void Squeeze(char s1[], char s2[])
 7 {
 8     for(int n = 0; s2[n] != '\0'; n++)
 9     {
10         int j = 0;
11         for(int i = 0; s1[i] != '\0'; i++)
12         {
13             if(s1[i] != s2[n]) 
14                 s1[j++= s1[i];
15         }
16         s1[j] = '\0';
17     }
18 }
19  
20 int main()
21 {    
22     char s1[100= {"aacciiifesdf"};
23     char s2[100= {"aif"};
24     Squeeze(s1, s2);
25     for(int i = 0; s1[i] != '\0'; i++)
26     {
27         putchar(s1[i]);
28     }
29     return 0;
30 }
31 


 

posted on 2010-07-16 10:01  ewee  阅读(243)  评论(0编辑  收藏  举报

导航