1050 String Subtraction
string
2023-09-11 14:22:44 时间
Given two strings S1 and S2, S=S1−S2 is defined to be the remaining string after taking all the characters in S2 from S1. Your task is simply to calculate S1−S2 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 S1 and S2, respectively. The string lengths of both strings are no more than 1. 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 S1−S2 in one line.
Sample Input:
They are students.
aeiou
Sample Output:
Thy r stdnts.
题意:
给出两个字符串,提出第一个字符串中,两个字符串都出现的字符。
思路:
模拟。
Code:
1 #include <bits/stdc++.h> 2 3 using namespace std; 4 5 int main() { 6 string s1, s2; 7 getline(cin, s1); 8 getline(cin, s2); 9 unordered_set<char> visited; 10 for (int i = 0; i < s2.length(); ++i) visited.insert(s2[i]); 11 string ans = ""; 12 for (int i = 0; i < s1.length(); ++i) 13 if (visited.find(s1[i]) == visited.end()) ans += s1[i]; 14 cout << ans << endl; 15 return 0; 16 }
相关文章
- C++的自定义的string类
- Leetcode: Decode String
- DataTable to byte[]、DataTable to XML(string)
- request:fail parameter error: parameter.url should be String instead of Undefined;
- JS 对象(Object)和字符串(String)互转
- String StringBuilder StringBuffer区别以及源码分析
- Convert string to binary and binary to string in C#
- JAVA字符串格式化-String.format()的使用 及 Android 中 string.xml 中 字符串格式转化
- Redis学习手册(String数据类型)
- [转]全面认识golang string
- string与QString之间的转换(两种方法:fromStdString直接转换,或者fromLocal8Bit(cstr.c_str())
- vue渲染列表时报错Avoid using non-primitive value as key, use string/number value instead.
- 字符串转码【String.getBytes()和new String()】
- 《C#零基础入门之百识百例》(三十九)常用方法 -- String类
- [LeetCode] Interleaving String 交织相错的字符串
- dotnet中Stream、string及byte[]的相关操作