The C Programming Language 练习题2-4
来源:互联网 发布:中国向何处去 知乎 编辑:程序博客网 时间:2024/06/04 18:03
题目
squeeze(s1, s2),将字符串s1 中任何与字符串s2 中字符匹配的字符都删除。
题目分析
先将s2中每个字符串拿出来在s1中寻找,然后生成不包含此字符的新的s1字符串,然后再找下一个。
编程实现
为了方便定位问题,加的打印信息较多。。。。(其实已经删掉许多打印了)
#include <stdio.h>#define MAXLINE 1000void squeeze(char s1[], char s2[]);int main(){ int i; char c, sfirst[MAXLINE], ssecond[MAXLINE]; i = 0; printf("Please input string1:"); while ((c = getchar()) != '\n') sfirst[i++] = c; sfirst[i] = '\0'; printf("The first string is:"); i = 0; while (sfirst[i] != '\0') printf("%c", sfirst[i++]); printf("\n"); i = 0; printf("Please input string2:"); while ((c = getchar()) != '\n') ssecond[i++] = c; ssecond[i] = '\0'; printf("The second string is:"); i = 0; while (ssecond[i] != '\0') printf("%c", ssecond[i++]); printf("\n"); squeeze(sfirst, ssecond); i = 0; while (sfirst[i] != '\0') { printf("%c",sfirst[i]); i++; }}void squeeze(char s1[], char s2[]){ int m, n, l; m = n = l = 0; for (n = 0; s2[n] != '\0'; n++) { for (m = l = 0; s1[m] != '\0'; m++) if (s1[m] != s2[n]) s1[l++] = s1[m]; s1[l] = '\0'; }}
阅读全文
0 0
- The C Programming Language 练习题2-4
- The C Programming Language 练习题4-2
- The C Programming Language 练习题2-2
- The C Programming Language 练习题3-4
- The C Programming Language 练习题4-1
- The C Programming Language 练习题4-3
- The C Programming Language 练习题4-5
- The C Programming Language 练习题4-6
- The C Programming Language 练习题2-1
- The C Programming Language 练习题2-3
- The C Programming Language 练习题2-5
- The C Programming Language 练习题2-6
- The C Programming Language 练习题2-7
- The C Programming Language 练习题2-8
- The C Programming Language 练习题2-9
- The C Programming Language 练习题2-10
- The C Programming Language 练习题3-2
- 《The C Programming Language II》练习题代码
- java基础2017-10-01
- 旋转数组(循环数组)的最小数字
- Matlab图像处理-亮度(灰度)变换问题
- select用法
- 终于找到不走全局proxy方案
- The C Programming Language 练习题2-4
- Shell脚本8种字符串截取方法总结
- [简单题]Human Readable Time(Python 实现)
- Linux常用命令
- 使用webpack犯过的一个错误
- jdk_API中文文档下载汇总
- HDU3247-(AC自动机+spfa+状压dp)
- k路合并_败者树算法
- C++常见面试题(三)-static总结