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 ...
随机推荐
- 【原创】frozenset集合函数入门及实例
函数作用 frozenset() 返回一个冻结的集合,冻结后集合不能再添加或删除任何元素.与之对应的是set函数,set无序排序且不重复,是可变的,有add(),remove()等方法. 函数原型 f ...
- 笔记本电脑、VM虚拟机、开发板三者网线连接互ping
笔者在做NFS挂接练习时,发现网上的资料大部分是笔记本电脑(以下简称PC)和虚拟机PING.PC和开发板PING,这样的方式不是我想要的.笔者需要使用无线网卡上网,使用有线网卡进行三者互PING.在开 ...
- PTA(BasicLevel)-1006换个格式输出整数
一 换格式输出整数 用字母 B 来表示“百”.字母 S 表示“十”,用 12...n 来表示不为零的个位数字 n(<10),换个格式来输出任一个不超过 3 位的正整数.例如 234 应该被 ...
- node.js(二)
今天我们学习如何运行起来一个项目,我还不会新建项目,所以我们打开一个小伙伴创建的项目,我用的开发工具是vscode 选择项目所在文件夹就好了. 打开后是这样子的 我们还要安装一下npm, 在这里安装, ...
- R语言学习笔记—朴素贝叶斯分类
朴素贝叶斯分类(naive bayesian,nb)源于贝叶斯理论,其基本思想:假设样本属性之间相互独立,对于给定的待分类项,求解在此项出现的情况下其他各个类别出现的概率,哪个最大,就认为待分类项属于 ...
- (数据科学学习手札48)Scala中的函数式编程
一.简介 Scala作为一门函数式编程与面向对象完美结合的语言,函数式编程部分也有其独到之处,本文就将针对Scala中关于函数式编程的一些常用基本内容进行介绍: 二.在Scala中定义函数 2.1 定 ...
- Hadoop学习总结之Map-Reduce的过程解析111
一.客户端 Map-Reduce的过程首先是由客户端提交一个任务开始的. 提交任务主要是通过JobClient.runJob(JobConf)静态函数实现的: public static Runnin ...
- C语言复习20170805
循环控制结构 重复处理次数时已知的循环称为计数控制的循环,若重复处理次数为未知,是由给定情况控制的,称为条件控制的循环. C语言提供for.while.do while三种循环语句实现循环结构. 循环 ...
- 《Java程序设计》课堂实践内容总结
<Java程序设计>课堂实践内容总结 实践一 要求 修改教材P98 Score2.java, 让执行结果数组填充是自己的学号: 提交在IDEA或命令行中运行结查截图,加上学号水印,没学号的 ...
- Microsoft .NET Framework 安装未成功(证书方面)
问题:在为windows7 sp1安装framework 4.6.2的时候,有两次证书方面的报错 // 错误1: 无法建立到信任根颁发机构的证书链 // 错误2: 已处理证书链,但是在不受信任的根证书 ...