开心消消乐

Time Limit: 2000/1000ms (Java/Others)

Problem Description:

大白最近喜欢上了开心消消乐,于是英语基础好的他准备让课文中英语句子也来充当游戏的主角。
规则如下:输入两个字符串,从第一个字符串中删除第二个字符串所出现的字符(包括空格)
1<=字符串的长度<=1000。

Input:

输入有多组数据
每个测试数据占用两行,第一行为第一个字符串,第二行为第二个字符串。

Output:

若第一个字符串不能被全部消除则输出删除后的字符串(如删剩下空格则输出空格),否则输出“YES”(不包括双引号)。
每个输出占一行

Sample Input:

They are students
aeiou

Sample Output:

Thy r stdnts
解题思路:这道题用java最好不过了,前提是要了解java的正则表达式,具体什么是正则表达式就问度娘吧。
AC之java代码:
 import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
while(scan.hasNext()){
String obj=scan.nextLine();
String str="["+scan.nextLine()+"]";
obj=obj.replaceAll(str,"");
if(obj.length()>0)System.out.println(obj);
else System.out.println("YES");
}
}
}

AC之C++代码(map容器,简单过):

 #include<bits/stdc++.h>
using namespace std;
int main(){
string s1,s2;
while(getline(cin,s1)&&getline(cin,s2)){
map<char,bool> mp;
bool flag=false;
for (int i=;s2[i]!='\0';++i)mp[s2[i]]=true;
for (int i=;s1[i]!='\0';++i)
if(!mp[s1[i]]){cout<<s1[i];flag=true;}//如果没有该字母,则直接输出该字符
if(flag)cout<<endl;
else cout<<"YES"<<endl;
}
return ;
}
05-11 22:41