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、 若某个单词无论操作与否都无法在字典中找得到,则输出空
相关文章推荐
- poj 1035 Spell checker
- POJ Spell checker(1035)-字符串处理
- POJ-1035-Spell checker
- POJ 1035 Spell checker (字符串)
- POJ1035-拼写检查
- poj_1035 串
- POJ - 1035 - Spell checker (暴力)
- poj 1035 Spell checker
- POJ 1035 解题报告
- poj1035 Spell checker
- poj1035_Spell checker
- poj 1035 Spell checker
- POJ 1035 Spell checker
- Spell checker(POJ--1035
- POJ 1035 Spell checker
- ACM-POJ1035 Spell checker [MyAnswer]
- POJ 1035
- POJ 1035 Spell checker【字符串暴力处理】
- POJ 1035 Spell checker(string)应用
- poj 1035 串的对比