当前位置:网站首页>[day_010418] delete public string
[day_010418] delete public string
2022-07-26 06:11:00 【On the Bank of Anhe Bridge】
Delete public string
Title source
Cattle from : Delete public characters
Title Description
Enter two strings , Remove all characters in the second string from the first string . for example , Input ”They are students.” and ”aeiou”, The first string after deletion becomes ”Thy r stdnts.”
Input description
Each test input contains 2 A string
Output description
Output the deleted string
Example 1
Input
They are students.
aeiouOutput
Thy r stdnts.
Thought analysis
- There is a space in the middle of the input string , So use getline() Function to get a string , Whole line reception
- Map the second string to a length of 256 Of Hash array in , Subscript representation of array ASCII value , The value of the array element indicates the number of times the character appears in the second string
- Traverse the first array , Judge whether the hash array value of the subscript corresponding to the character is 0, Use "+=" Splicing
Code display
#include<iostream>
#include<string>
using namespace std;
int main()
{
int hash[256]={
0};
string str1;
string str2;
string str="";
getline(cin,str1);
getline(cin,str2);
// Traversing the second string , Map characters to an array
for(int i=0;i<str2.size();i++)
{
hash[str2[i]]++;
}
// Traverse the first array
for(int i=0;i<str1.size();i++)
{
if(hash[str1[i]]==0)
{
str+=str1[i];// Splicing
}
}
cout<<str<<endl;
return 0;
}
边栏推荐
- Blurring of unity pixel painting
- L. Link with Level Editor I dp
- [2023 Jerry technology approval test questions in advance] ~ questions and reference answers
- Kingbasees SQL language reference manual of Jincang database (11. SQL statement: abort to alter index)
- Unity2d animator cannot create transition
- Mysql45 talking about global lock, table lock and row lock
- Operating steps for uninstalling the mobile app
- Unity2D 动画器无法 创建过渡
- The time complexity of two recursive entries in a recursive function
- Establishment of log collection and analysis platform-1-environment preparation
猜你喜欢

Leetcode:336. palindrome pair

【Day04_0421】C语言选择题

Understanding the mathematical essence of machine learning

VS中使用动态库

Day110. Shangyitong: gateway integration, hospital scheduling management: Department list, statistics based on date, scheduling details

Knowledge precipitation I: what does an architect do? What problems have been solved

招标信息获取

CV (1)- Introduction

H. Take the Elevator 贪心

Traversal of the first, middle, and last order of a binary tree -- Essence (each node is a "root" node)
随机推荐
Using dynamic libraries in VS
[Oracle SQL] calculate year-on-year and month on month (column to row offset)
Ganglia installation and deployment process
光量子里程碑:6分钟内解决3854个变量问题
2022 National latest fire-fighting facility operator (Senior fire-fighting facility operator) simulation test questions and answers
flex布局
Matlab vector and matrix
H. Take the Elevator 贪心
Knowledge precipitation I: what does an architect do? What problems have been solved
The time complexity of two recursive entries in a recursive function
Flex layout
Code Runner for VS Code,下载量突破 4000 万!支持超过50种语言
Excitation method and excitation voltage of hand-held vibrating wire vh501tc acquisition instrument
Amd zen4 game God u reached 208mb cache within this year, which is unprecedented
Full binary tree / true binary tree / complete binary tree~
Database SQL language practice
Introduction of four redis cluster schemes + comparison of advantages and disadvantages
YOLOv7: Trainable bag-of-freebies sets new state-of-the-art for real-time object detectors
【Day_06 0423】把字符串转换成整数
英语句式参考纯享版 - 状语从句