题解 | #删除公共字符#
删除公共字符
https://www.nowcoder.com/practice/f0db4c36573d459cae44ac90b90c6212
import java.util.*; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNextLine()) { String str1 = sc.nextLine(); String str2 = sc.nextLine(); //char[] ch = str2.toCharArray(); String[] str = str1.split(" "); StringBuilder sb = new StringBuilder(); for (String i : str) { String str3 = i; for (int k = 0; k < str2.length(); k++) { char ch = str2.charAt(k); if (i.contains(ch + "")) { str3 = str3.replaceAll(ch + "",""); } } sb.append(str3 + " "); } String str4 = sb.toString(); str4 = str4.trim(); System.out.println(str4); } } }