题目链接
用要删字符的他们的ascii码作为数组元素下标来进行存储,对于所要判断的字符串如果满足,则不输出
// ConsoleApplication1.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
#pragma warning(disable:4996);
#include <iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<stack>
using namespace std;
int main()
{
int keyboard[128] = { 0 };
char ch;
while ((ch = getchar()) != '\n')
{
keyboard[ch] = -1;//如果是小写转成大写,对其他字符没有用;
}//待删除字符的记录;
while ((ch = getchar()) != '\n') {
if ((keyboard[toupper(ch)] == -1) || (isupper(ch) && keyboard['+'] == -1))
{//如果是要删字符,还要考虑如果有加号,大写字母也要去除
continue;
}
putchar(ch);
}
putchar('\n');
return 0;
}