您的位置:首页 > 其它

poj 1035

2012-06-10 14:19 211 查看
package com.liang.poj;

import java.util.ArrayList;
import java.util.Scanner;

public class Test1035 {
static boolean n = true;
static boolean b1 = true;

static ArrayList<String> array1 = new ArrayList<String>();
static ArrayList<String> array2 = new ArrayList<String>();

public static void main(String[] args) throws Exception {
Scanner scan = new Scanner(System.in);
while (scan.hasNext()) {
String str = scan.nextLine();
if (str.equals("#")) {
break;
} else {
array1.add(str);
}
}
while (scan.hasNext()) {
String str = scan.nextLine();
if (str.equals("#")) {
break;
} else {
array2.add(str);
}
}

for (int i = 0; i < array2.size(); i++) {
String str1 = array2.get(i);
boolean b = true;
for (int j = 0; j < array1.size(); j++) {
String str2 = array1.get(j);
if (str2.equals(str1)) {
System.out.println(str1 + " is correct");
b = false;
n = false;
break;
}
}

if (b) {
for (int j = 0; j < array1.size(); j++) {
String str2 = array1.get(j);
if (str2.length() == str1.length()) {
chang(str1, str2);
}

if (str1.length() == str2.length() - 1) {
add(str1, str2, 0);
}

if (str1.length() == str2.length() + 1) {
add(str2, str1, 1);
}
}
if (!n)
System.out.println();
}
if (n) {
System.out.println(str1 + ":");
}
n = true;
b1 = true;
}

}

public static void chang(String str1, String str2) {
int count = 0;
for (int i = 0; i < str1.length(); i++) {
if (str1.charAt(i) != str2.charAt(i)) {
count++;
}
}
if (count == 1) {
n = false;
if (b1) {
b1 = false;
System.out.print(str1 + ": " + str2 + " ");
} else {
System.out.print(str2 + " ");
}
}
}

public static void add(String str1, String str2, int tag) {
int count = 0;
for (int i = 0; i < str1.length(); i++) {
String str = str1.substring(i, i + 1);
if (!str2.contains(str)) {
count++;
}
}
if (count == 0 && tag == 0) {
n = false;
if (b1) {
b1 = false;
System.out.print(str1 + ": " + str2 + " ");
} else {
System.out.print(str2 + " ");
}
} else if (count == 0 && tag == 1) {
n = false;
if (b1) {
b1 = false;
System.out.print(str2 + ": " + str1 + " ");
} else {
System.out.print(str1 + " ");
}

}

}

}


大致题意:

输入一部字典,输入若干单词

1、 若某个单词能在字典中找到,则输出corret

2、 若某个单词能通过 变换删除添加一个字符后,在字典中找得到,则输出这些单词,输出顺序根据 输入的那部字典的字典序

3、 若某个单词无论操作与否都无法在字典中找得到,则输出空
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: