PAT_A 1050. String Subtraction (20)
来源:互联网 发布:使命召唤14优化怎么样 编辑:程序博客网 时间:2024/06/14 02:35
1050. String Subtraction (20)
Given two strings S1 and S2, S = S1 - S2 is defined to be the remaining string after takingall the characters in S2 from S1. Your task is simply to calculate S1 - S2 for any givenstrings. 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 104. 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.aeiouSample Output:Thy r stdnts.
分析:
- 题目:输出在s1中的字符,但不在s2中的字符
- 解题:利用hash,对s2中的字符做个存在标识,s1输出中,检查标识,不存在2中则输出
code:
#include<iostream>#include<cstdio>using namespace std;int s[500];int main(){ freopen("in","r",stdin); string s1,s2; fill_n(s,0,500); getline(cin,s1); getline(cin,s2); for(int i=0;i<s2.length();i++) s[int(s2[i])]=1; for(int i=0;i<s1.length();i++) { if(s[int(s1[i])]==0) cout<<s1[i]; } cout<<endl; return 0;}
- AC:
阅读全文
0 0
- PAT_A 1050. String Subtraction (20)
- 1050. String Subtraction (20)
- 1050. String Subtraction (20)
- 1050. String Subtraction (20)
- 1050. String Subtraction (20)
- 1050. String Subtraction (20)
- 1050. String Subtraction (20)
- 1050. String Subtraction (20)
- 1050. String Subtraction (20)
- 1050. String Subtraction (20)
- 1050. String Subtraction (20)
- 1050. String Subtraction (20)
- 1050. String Subtraction (20)
- 1050. String Subtraction (20)
- 1050. String Subtraction (20)
- 1050. String Subtraction (20)
- 1050. String Subtraction (20)
- 1050. String Subtraction (20)
- python Day3
- 单例设计模式
- iOS开发之旅(2):实现一个APP界面框架之搜索功能
- Opencv学习——图像分割之分水岭算法
- JAVA 映射网站到外网
- PAT_A 1050. String Subtraction (20)
- hdu2102 A计划
- 雪国,只不过是一场徒劳
- JMeter关联之正则表达式提取器
- java 面试全集(上)
- POJ 3254 Corn Fields(状压DP)
- 三种方法求连续子数组的最大和
- 安卓:Intent的各种跳转系统页面
- Linux文件系统小结