字符串去特定字符--九度教程1049

题目描述:

输入字符串s和字符c,要求去掉s中所有的c字符,并输出结果。

输入:

测试数据有多组,每组输入字符串s和字符c。

输出:

对于每组输入,输出去除c字符后的结果。

样例输入:

heallo
a

样例输出:

hello

来源:

2009年哈尔滨工业大学计算机研究生机试真题

 解答:

比较简单,注意输入流中,要getchar()

#include <stdio.h>
#include <string.h>

using namespace std;


int main()
{
	char str[200];
	char c;
	while (scanf("%s",str)!=EOF)
	{
		getchar();
		scanf("%c", &c);
		int len = strlen(str);
		for (int i = 0; i < len; i++) {
			if (str[i] != c) printf("%c", str[i]);
		}
		printf("\n");
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/baidu_39622935/article/details/81394785