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 ...
随机推荐
- go语言Mutex与RWMutex用法
Mutex(互斥锁) Lock()加锁,Unlock()解锁 适用于读写不确定,并且只有一个读或者写的场景 例: package main import ( "sync" &quo ...
- ubuntu下pycharm快捷方式创建
终端输入:sudo gedit /usr/share/applications/Pycharm.desktop 粘贴模板: [Desktop Entry] Type=Application Name= ...
- 版本控制工具(下)——Git的远程仓库、分支管理与其它操作
预备知识: SSH协议参考资料:http://blog.csdn.net/vevenlcf/article/details/43273405 图解公钥和私钥:http://blog.csdn.net/ ...
- 20155305 2016-2017-2 《Java程序设计》实验二 Java面向对象程序设计
实验二 Java面向对象程序设计 实验内容 初步掌握单元测试和TDD 理解并掌握面向对象三要素:封装.继承.多态 初步掌握UML建模 熟悉S.O.L.I.D原则 了解设计模式 实验步骤 单元测试 1. ...
- 20155325 2016-2017-2 《Java程序设计》第4周学习总结
教材学习内容总结 封装就是将数据与相关行为包装在一起以实现信息就隐藏. 多态是指不同的类对象调用同一个签名的成员方法时将执行不同代码的现象.多态是面向对象程序设计的灵活性和可扩展性的基础. 以封装为基 ...
- 20155327 嵌入式C语言课堂补交
嵌入式C语言 题目要求 在作业本上完成附图作业,要认真看题目要求. 提交作业截图 作弊本学期成绩清零(有雷同的,不管是给别人传答案,还是找别人要答案都清零) 题目分析 分析一:提取插入时间 根据老师上 ...
- Qt QStringLiteral
zz 解释QStringLiteral 原文发表于woboq网站 QStringLiteral explained 转载 原作者: Olivier Goffart 译者:zzjin QStringL ...
- springboot-vue-JWT使用
springboot-vue-JWT使用 后端引入依赖: <dependency> <groupId>io.jsonwebtoken</groupId> <a ...
- 一个非常好用的PHP数组函数
array_column 该函数非常有用,在PHP 5.5中可直接调用. 有如下二维数组,如要抽取每个子数组中的特定项. <?php // Array representing a possib ...
- iOS 小技巧
投影效果 scanBtn.layer.shadowColor = [UIColorblackColor].CGColor;//shadowColor阴影颜色 scanBtn.layer.sha ...