PATA1050 String Subtraction

举报
陈沧夜 发表于 2022/04/30 00:50:29 2022/04/30
【摘要】 1050 String Subtraction 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 ...

1050 String Subtraction

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:


  
  1. They are students.
  2. aeiou

Sample Output:

Thy r stdnts.
 

  
  1. #include<cstdio>
  2. #include<iostream>
  3. #include<cstring>
  4. #include<algorithm>
  5. using namespace std;
  6. int main()
  7. {
  8. // freopen("C://坚果云//算法//String Subtractionin.txt","r",stdin);
  9. // freopen("C://坚果云//算法//String Subtractionout.txt","w",stdout);
  10. bool b[1000];
  11. string a,c;
  12. getline(cin,a);
  13. getline(cin,c);
  14. for(int i=0;i<1000;i++)
  15. {
  16. b[i]=true;
  17. }
  18. for(int j=0;j<c.length();j++)
  19. {
  20. b[c[j]]=false;
  21. }
  22. for(int j=0;j<a.length();j++)
  23. {
  24. if(b[a[j]]==true)
  25. {
  26. printf("%c",a[j]);
  27. }
  28. }
  29. // fclose(stdin);
  30. // fclose(stdout);
  31. return 0;
  32. }

 

文章来源: blog.csdn.net,作者:沧夜2021,版权归原作者所有,如需转载,请联系作者。

原文链接:blog.csdn.net/CANGYE0504/article/details/88836364

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。