Given two strings S1 and S2, S=S1−S2 is defined to be the remaining string after taking all the characters in S2 from S1. Your task is simply to calculate S1−S2 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 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.
aeiou
Sample Output:
Thy r stdnts.
1 package pattest; 2 3 import java.io.BufferedReader; 4 import java.io.IOException; 5 import java.io.InputStreamReader; 6 7 /** 8 * @Auther: Xingzheng Wang 9 * @Date: 2019/2/23 15:50 10 * @Description: pattest 11 * @Version: 1.0 12 */ 13 public class PAT1050 { 14 public static void main(String[] args) throws IOException { 15 BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); 16 String s1 = reader.readLine(); 17 String s2 = reader.readLine(); 18 char[] ch = s2.toCharArray(); 19 for (char c : ch){ 20 s1 = s1.replaceAll(String.valueOf(c),"" ); 21 } 22 System.out.print(s1); 23 } 24 }
本文介绍了一个简单的字符串处理问题,即计算两个字符串S1和S2的差集S1-S2,通过去除S1中所有出现在S2中的字符。使用Java实现,通过读取输入的两个字符串,将第二个字符串的每个字符从第一个字符串中移除,并输出结果。
375

被折叠的 条评论
为什么被折叠?



