0
点赞
收藏
分享

微信扫一扫

1093 字符串A+B(JAVA)


给定两个字符串 A 和 B,本题要求你输出 A+B,即两个字符串的并集。要求先输出 A,再输出 B,但重复的字符必须被剔除

输入格式:

输入在两行中分别给出 A 和 B,均为长度不超过 106的、由可见 ASCII 字符 (即码值为32~126)和空格组成的、由回车标识结束的非空字符串。

输出格式:

在一行中输出题面要求的 A 和 B 的和。

输入样例:

This is a sample test
to show you_How it works

输出样例:

This ampletowyu_Hrk

代码实现:

import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Locale;

/**
* @author yx
* @date 2022-07-26 21:55
*/
public class Main {
static PrintWriter out=new PrintWriter(System.out);
static BufferedReader ins=new BufferedReader(new InputStreamReader(System.in));
static StreamTokenizer in=new StreamTokenizer(ins);

public static void main(String[] args) throws IOException {
String A=ins.readLine();
String B=ins.readLine();
HashMap<Character,Integer> map=new HashMap<>();
for (int i = 0; i < A.length(); i++) {
if(!map.containsKey(A.charAt(i))){
map.put(A.charAt(i),1);
System.out.print(A.charAt(i));
}
}
for (int i = 0; i < B.length(); i++) {
if(!map.containsKey(B.charAt(i))){
map.put(B.charAt(i),1);
System.out.print(B.charAt(i));
}
}
}
}

1093 字符串A+B(JAVA)_i++

 

举报

相关推荐

0 条评论