import java.util.*; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); String str1 = in.nextLine(); String str2 = in.nextLine(); HashMap map = new HashMap(); //遍历第二个字符串 for (int i = 0; i < str2.length(); i++) { //判断当前拿到的字符,之前是否存在于 map 中 if (map.get(str2.charAt(i)) == null) { map.put(str2.charAt(i), 1); } else { //之前存在,就在上一次的基础上加1: map.get(str2.charAt(i)) + 1 map.put(str2.charAt(i), map.get(str2.charAt(i)) + 1); } } String ret = ""; //遍历第一个字符串 for (int i = 0; i < str1.length(); i++) { if (map.get(str1.charAt(i)) == null) { ret += str1.charAt(i); } } System.out.println(ret); } }
import java.util.*; public class Main { public static void main(String[] args){ Scanner sc = new Scanner(System.in); while(sc.hasNextLine()){ String s1 = sc.nextLine(); String s2 = sc.nextLine(); StringBuilder sb = new StringBuilder(); Set<Character> set = new HashSet<>(); for(int i = 0;i < s2.length();i++){ set.add(s2.charAt(i)); } for(int i = 0;i < s1.length();i++){ if(!set.contains(s1.charAt(i))){ sb.append(s1.charAt(i)); } } System.out.println(sb.toString()); } } }
import java.util.*; public class Main{ public static void main(String[] args) { Scanner scanner=new Scanner(System.in); String act=scanner.nextLine(); String del=scanner.next(); Set<Character> delstr=new HashSet<>(); for (int i=0;i<del.length();i++) { delstr.add(del.charAt(i)); } for (int i=0;i<act.length();i++) { char c=act.charAt(i); if (!delstr.contains(c)) { System.out.print(c); } } } }
import java.util.*; public class Main{ public static void main(String[] args) { Scanner scan = new Scanner(System.in); String s = scan.nextLine(); String del = scan.nextLine(); HashSet<Character> set = new HashSet<>(); for (char ch : del.toCharArray()) { if (!set.contains(ch)) { set.add(ch); } } StringBuilder str = new StringBuilder(); for (char ch : s.toCharArray()) { if (!set.contains(ch)) { str.append(ch); } } System.out.println(str.toString()); } }
import java.util.Scanner; import java.util.*; public class Main{ public static String delStr(String str1,String str2){ for(int i=0;i<str1.length();i++){ for(int j=0;j<str2.length();j++){ if(str2.charAt(j)==str1.charAt(i)){ str1 = str1.replace(str1.charAt(i)+"",""); } } } return str1; } public static void main(String[] args){ Scanner s = new Scanner(System.in); String str1 = s.nextLine(); String str2 = s.nextLine(); System.out.print(delStr(str1,str2)); } }
import java.util.Scanner; public class DeletePublicString { public static void main(String args[]){ Scanner sc = new Scanner(System.in); String a = sc.nextLine(); String b = sc.nextLine(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < a.length() ; i++) { if(a.charAt(i)==' '||!b.contains(String.valueOf(a.charAt(i)))){ sb.append(a.charAt(i)); } } System.out.println(sb.toString()); } }
用正则表达式
import java.util.*; public class Main { public static void main(String [] args) { Scanner sc=new Scanner(System.in); while(sc.hasNextLine()) { String a=sc.nextLine(); String b=sc.nextLine(); String regex="["+b+"]";//动态正则表达式 String c=a.replaceAll(regex, ""); System.out.println(c); } } }
import java.util.*; public class Main{ //思路:利用Set的不可重复 public static String deleteComCha(String string1,String string2) {Set<Character> temp=new HashSet<>(); for(char c:string2.toCharArray()) {temp.add(c);} //遍历第一个字符串 for (int i=0;i<string1.length();i++) { if(temp.add(string1.charAt(i))==false) {string1=string1.substring(0,i)+string1.substring(i+1,string1.length()); i--;} else temp.remove(string1.charAt(i)); } return string1; } public static void main(String[] args) { Scanner in=new Scanner(System.in); String string1=in.nextLine(); String string2=in.nextLine(); System.out.println(deleteComCha(string1,string2)); } }
import java.util.*; public class Main{ public static void main(String []args){ Scanner in=new Scanner(System.in); String first=in.nextLine(); String second=in.next(); String rs=""; int []flag=new int [256]; for(int i=0;i<second.length();i++){ int temp=second.charAt(i); if(flag[temp]==0) flag[temp]=1; } for(int i=0;i<first.length();i++){ int temp=first.charAt(i); if(flag[temp]==0) rs+=first.charAt(i); } System.out.print(rs); } }
import java.util.Scanner; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); while(sc.hasNext()){ char[] ch = sc.nextLine().toCharArray(); String str = sc.nextLine(); for(int i=0;i<ch.length;i++){ if(!str.contains(String.valueOf(ch[i]))){ System.out.print(ch[i]); } } System.out.println(); } } }