1093 字符串A+B

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

输入格式:

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

输出格式:

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

输入样例:

This is a sample test
to show you_How it works

输出样例:

This ampletowyu_Hrk

作者: 陈越

单位: 浙江大学

时间限制: 400 ms

内存限制: 64 MB

代码长度限制: 16 KB


import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner in= new Scanner(System.in);
		String a = in.nextLine();
		String b = in.nextLine();
		String s = a+b;
		char ch[] = new char[100];
		ch = s.toCharArray();
		int arr[] = new int[100];
		for(int i=0;i<ch.length;i++)
		{
			arr[ch[i]-' ']++;
			if(arr[ch[i]-' ']==1)
			{
				System.out.print(ch[i]);
			}
		}

	}

}

猜你喜欢

转载自blog.csdn.net/apity123/article/details/86472092