PAT 甲级 1050 String Subtraction
https://pintia.cn/problem-sets/994805342720868352/problems/994805429018673152
Given two strings S~1~ and S~2~, S = S~1~ - S~2~ is defined to be the remaining string after taking all the characters in S~2~ from S~1~. Your task is simply to calculate S~1~ - S~2~ for any given strings. However, it might not be that simple to do it fast.
Input Specification:
Each input file contains one test case. Each case consists of two lines which gives S~1~ and S~2~, respectively. The string lengths of both strings are no more than 10^4^. It is guaranteed that all the characters are visible ASCII codes and white space, and a new line character signals the end of a string.
Output Specification:
For each test case, print S~1~ - S~2~ in one line.
Sample Input:
They are students.
aeiou
Sample Output:
Thy r stdnts.
代码:
#include <bits/stdc++.h>
using namespace std; const int maxn = 1e5 + 10;
char s1[maxn], s2[maxn]; int main() {
cin.getline(s1, maxn);
cin.getline(s2, maxn);
int len1 = strlen(s1), len2 = strlen(s2);
for(int i = 0; i < len1; i ++) {
for(int j = 0; j < len2; j ++) {
if(s1[i] == s2[j])
s1[i] = '*';
}
} for(int i = 0; i < len1; i ++) {
if(s1[i] != '*')
printf("%c", s1[i]);
}
printf("\n");
return 0;
}
PAT 甲级 1050 String Subtraction的更多相关文章
- PAT 甲级 1050 String Subtraction (20 分) (简单送分,getline(cin,s)的使用)
1050 String Subtraction (20 分) Given two strings S1 and S2, S=S1−S2 is defined to be t ...
- PAT甲级——1050 String Subtraction
1050 String Subtraction Given two strings S1 and S2, S=S1−S2 is defined to be the remain ...
- PAT Advanced 1050 String Subtraction (20 分)
Given two strings S1 and S2, S=S1−S2 is defined to be the remaining string after taking ...
- PAT甲级——A1050 String Subtraction
Given two strings S1 and S2, S=S1−S2 is defined to be the remaining string after taking ...
- PAT Advanced 1050 String Subtraction (20) [Hash散列]
题目 Given two strings S1 and S2, S = S1 – S2 is defined to be the remaining string afer taking all th ...
- PAT练习--1050 String Subtraction (20 分)
题⽬⼤意:给出两个字符串,在第⼀个字符串中删除第⼆个字符串中出现过的所有字符并输出. 这道题的思路:将哈希表里关于字符串s2的所有字符都置为true,再对s1的每个字符进行判断,若Hash[s1[i] ...
- PAT 解题报告 1050. String Subtraction (20)
1050. String Subtraction (20) Given two strings S1 and S2, S = S1 - S2 is defined to be the remainin ...
- PAT 1050 String Subtraction
1050 String Subtraction (20 分) Given two strings S1 and S2, S=S1−S2 is defined to be t ...
- pat 1050 String Subtraction(20 分)
1050 String Subtraction(20 分) Given two strings S1 and S2, S=S1−S2 is defined to be the ...
随机推荐
- PTA基础编程题目集6-5求自定类型元素的最大值 (函数题)
原题目: 本题要求实现一个函数,求N个集合元素S[]中的最大值,其中集合元素的类型为自定义的ElementType. 函数接口定义: ElementType Max( ElementType S[], ...
- python学习之路-基本数据类型1 变量的概念、数字、字符串
1 什么是数据类型? 每种编程语言都有自己的数据类型,用于标识计算机可以认识的数据,Python中主要的数据类型为字符串,整数,浮点数,列表,元祖,字典,集合七种主要的数据类型,其中以列表,字典为最主 ...
- ASP.NET底层与各个组件的初步认识与理解 (转载)
ASP.NET底层的初步认识与理解 最近在国外的网站乱走一通,发现一些比较好的文章,收集整理加于自己的理解,作为笔记形式记录下来,让以后自己有个回忆. ASP.NET是一个非常强大的构建Web应用 ...
- 20155223 2006-2007-2 《Java程序设计》第3周学习总结
20155223 2006-2007-2 <Java程序设计>第3周学习总结 教材学习内容总结 第四章 有点好奇:为什么Java编程语言一定要使用java.math.BigDecimal才 ...
- PostgreSQL的checkpoint能否并行
对于此问题,在社区进行了提问,并得到了一些大牛的解答: http://postgresql.1045698.n5.nabble.com/Can-checkpoint-creation-be-paral ...
- Java——基于java自身包实现消息系统间的通信(TCP/IP+BIO)
最近看到阿里的一位童鞋写的一本关于分布式的书,感觉不错,准备把这本书上基础的代码都写一写. /** * Created by LiuHuiChao on 2016/11/15. * descripti ...
- OpenStack入门篇(七)之认证服务Keystone
一.Keystone的概述 Keystone是Openstack的组件之一,用于为Openstack家族中的其它组件成员提供统一的认证服务,包括身份验证,令牌的发放和校验,服务列表,用户权限的定义等. ...
- httpclient在获取response的entity时报异常
httpClient报异常:Premature end of chunk coded message body: closing chunk expected 首先这个异常提示直译过来就是:被编码信息 ...
- 每周开源项目分享-年轻人的第一个OAuth2.0 Server:hydra
年轻人的第一个OAuth2.0 Server:hydra hydra 是什么呢? OpenID Connect certified OAuth2 Server - cloud native, secu ...
- JavaScript的数组和字符串应用
函数search实现在一个已排序的数字类型数组中查找指定数字的功能. 可以采用数组的内置方法,二分查找法等进行操作 //方法一 var search = function(arr,dst){ var ...