uva 10815-UVa-10815 Andy's First Dictionary

问题描述

UVa-10815 Andy's First Dictionary

题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=18649
以下是我的java代码:

 package UVaOJ;

import java.util.Scanner;
import java.util.TreeSet;

public class Main {

    public static String filter(String s){
        StringBuilder sb = new StringBuilder();
        for(char c:s.toCharArray()){
            if(Character.isAlphabetic(c)) sb.append(c);
            else sb.append(" ");
        }
        return sb.toString();
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        TreeSet<String> ts = new TreeSet<String>();
        while(sc.hasNext()){
            String s = filter(sc.nextLine().toLowerCase());
            String[] str = s.split(" +");
            for(String ss:str){
                if(ss != "") ts.add(ss);
            }
        }
        for(String s:ts){
            System.out.println(s);
        }
        sc.close();

    }

}

提交WA,求解~

解决方案

String[] str = s.split(" +");
->
String[] str = s.split("s+");

解决方案二:

String[] str = s.split("\s+");

解决方案三:

TreeSet不会去重吧。你需要一个判断。

解决方案四:

 用Character.isLetter
呢

if(ss != "") ts.add(ss);
->
if(!ss.equals("")) ts.add(ss);

增加点日志输出看下
System.out.println("---filter" + sb.toString());
return sb.toString();

解决方案五:

s+改了还是WA

解决方案六:

"s+"改了还是WA

解决方案七:

噗。。。\s+改了还是WA

时间: 2024-09-10 19:03:44

uva 10815-UVa-10815 Andy&amp;#39;s First Dictionary的相关文章

uva 10688:The Poor Giant(区间dp)

题目链接: uva-10688 http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=514&page=show_problem&problem=1629 题意 有n个苹果,和一个数k,第i个苹果的重量是k+i(1<=i<=n). 已知其中只有一个苹果是甜的, 所有比它重量轻的都是苦的,比它重的都是酸的. 为了要找出甜的苹果,就要去一个一个地吃它,且吃了咬了苹果

UVa 10125:Sumsets

题目链接: UVa : http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1066 poj :   http://poj.org/problem?id=2549 类型: 哈希, 二分查找 原题: Given S, a set of integers, find the largest d such that a

UVa 10887:Concatenation of Languages

链接: UVa :  http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1828 类型:  哈希表 原题: A language is a set of strings. And the concatenation of two languages is the set of all strings that a

UVa 10670:Work Reduction

[链接] UVA:  http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=113&page=show_problem&problem=1611 poj:     http://poj.org/problem?id=1907 [原题] Paperwork is beginning to pile up on your desk, and tensions at the wo

UVa 10391:Compound Words

题目链接: UVa: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1332 zoj :  http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=825 类型: Hash 原题: You are to find all the two-word

UVa 11503:Virtual Friends

题目链接: UVa : http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=2498 HDU: http://acm.hdu.edu.cn/showproblem.php?pid=3172 类型:   并查集, 哈希 原题: These days, you can do all sorts of things on

UVa 10274:Fans and Gems, 神牛Rujia Liu的神题(三)

题目链接: UVa :  http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1215 zoj    : http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1237 类型:  隐式图搜索+恶心模拟+哈希判重+bfs+dfs 原题: Tomy's

用试探回溯法解决N皇后问题

学校数据结构的课程实验之一. 数据结构:(其实只用了一个二维数组) 算法:深度优先搜索,试探回溯 需求分析: 设计一个在控制台窗口运行的"n皇后问题"解决方案生成器,要求实现以下功能: 由n*n个方块排成n行n列的正方形称为n元棋盘.如果两个皇后位于n元棋盘上的同一行.同一列或同一对角线上,则称它们在互相攻击.现要找出使棋盘上n个皇后互不攻击的布局. 编制程序解决上述问题,以n=6运行程序,输出结果. 算法解释: 首先试探当前行第一个可用的位置(列.对角线没有被占领),摆放皇后之后,试

[置顶]群蚁算法理论与实践全攻略——旅行商等路径优化问题的新方法【附C#群蚁算法完整项目代码】

若干年前读研的时候,学院有一个教授,专门做群蚁算法的,很厉害,偶尔了解了一点点.感觉也是生物智能的一个体现,和遗传算法.神经网络有异曲同工之妙.只不过当时没有实际需求学习,所以没去研究.最近有一个这样的任务,所以就好好把基础研究了一下,驱动式学习,目标明确,所以还是比较快去接受和理解,然后写代码实现就好了.今天就带领大家走近TSP问题以及群蚁算法.  机器学习目录:[目录]数据挖掘与机器学习相关算法文章总目录 本文原文地址:群蚁算法理论与实践全攻略--旅行商等路径优化问题的新方法  1.关于旅行