PAT1093 字符串A+B

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.SimpleDateFormat;
import java.util.*;
public class Main {
	
	public static void main(String[] args) throws IOException {
		HashSet hs = new HashSet();
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        String line = null;
        StringBuilder res = new StringBuilder();
        while ((line=bf.readLine()) != null) {
			int length = line.length();
			for (int i = 0; i < length; i++) {
				char c = line.charAt(i);
				if (!hs.contains(c)) {
					hs.add(line.charAt(i));
					res.append(c);
				}
			}
		}
        System.out.println(res);
        
        		
	}
}

题目如题,方法:1、利用hashset不重复且底层是哈希表实现查找快的特点。2、Stringbuilder快速且附加操作方便

你可能感兴趣的:(Java,oj)