PAT (甲级)1050 String Subtraction (20point(s))

题目

题目链接

思路

题目大意:把s2中出现的字符从s1中删除,并不需要真的删除,只要对s2中的每个字符做上标记,遍历s1时如果某个字符标记过不输出就可以了;
题目虽然简单,但还是有两个知识点的;
1、gets函数不能通过编译,要使用 cin.getline(字符数组名,字符长度,结束符),其中结束符默认为 \n;
fetchar(); //读取多余字符,包括回车和空格;
getline(cin, string); //读取一行到string中,可以读取回车;
2、阿斯克码表一共有128个字符,包括可见的不可见的,最后一个是 delete;

代码
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
const int maxn = 1e5 + 10;

int main()
{
     char s1[100000], s2[100000];
     bool exist[200];
     fill(exist, exist + 200, true);
     cin.getline(s1, 100000);
     cin.getline(s2, 100000);
     int a = strlen(s1), b = strlen(s2);
     //将s2中的字符标记为不存在,即不能输出
     for(int i = 0; i < b; i ++){
          exist[s2[i]] = false;
     }
     for(int i = 0; i < a; i ++){
          //如果存在才会输出
          if(exist[s1[i]] == true) printf("%c", s1[i]);
     }
     system("pause");
     return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值