uva-10815 - Andy's First Dictionary

来源:互联网 发布:sql where执行顺序 编辑:程序博客网 时间:2024/06/06 02:29

题意:给你数个字符串,要你把字符串中的所以出现单词,不重复的按字典序输出。

思路:切割字符串,然后使用set存储单词

package test;import java.util.Scanner;import java.util.TreeSet;public class Test{static TreeSet<String> tree = new TreeSet<String>();public static void main(String[] args) {Scanner sc = new Scanner(System.in);String line = null;while(!"".equals((line=sc.nextLine().toLowerCase()))){for(String s : line.split(" ")){tree.add(s);}}System.out.println(tree);sc.close();}}


0 0
原创粉丝点击