Last active
January 3, 2016 05:58
-
-
Save novnan/8419100 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 输入一个字符串,存放在数组s1中,然后再输入一个字符串s2,在字符串s1中查找s2,并将找到的s2 | |
删除,重复这一过程,直到删除了s1中包含的所有s2,最后打印删除了所有s2的字符串s1 */ | |
#include <stdio.h> | |
#include <string.h> | |
void main() | |
{ | |
char s1[256], s2[256], s3[256]; | |
int i, j; | |
printf("输入字符串s1:"); | |
gets(s1); | |
printf("输入要删除的字符串s2:"); | |
gets(s2); | |
int x = 0; | |
int k = 0; | |
int equal; | |
for(i = 0; i < strlen(s1); i++) | |
{ | |
equal = 1; // jia she xiang deng. | |
for(j = 0, k = i; j < strlen(s2); j++) | |
{ | |
if(s2[j] != s1[k]) | |
{ | |
equal = 0; | |
break; | |
} | |
k++; | |
} | |
if (equal == 0) // bu xiang deng | |
{ | |
s3[x] = s1[i]; | |
x++; | |
} else { | |
i = k - 1; | |
} | |
} | |
s3[x == 0 ? x : x+1] = '\0'; | |
printf("删除后的字符串是:%s\n", s3); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment