poj 1035
来源:互联网 发布:linux查询服务器端口 编辑:程序博客网 时间:2024/05/01 11:42
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
- Poj 1035
- POJ 1035
- poj 1035
- poj 1035
- poj 1035
- poj 1035
- POJ 1035
- poj.1035
- poj-1035
- poj 1035
- poj 1035
- poj 1035
- POJ 1035
- POJ 1035
- poj 1035
- poj-1035-Spell checker
- poj 1035 Spell checker
- Android AsyncTask
- in和exists的区别与SQL执行效率分析
- GC工作原理详解
- 数据结构(C语言版)总结
- 优先级 (<<) 和 (+)
- poj 1035
- keepalived+nginx实现双机热备
- Android 不可缺少的异步(Thread、Handler、AsyncTask)
- Cocos2d中各种坐标位置关系
- cocos2d 坐标系使用
- Mysqlbackup 备份详解(mysql官方备份工具)
- BP人工神经网络的C++实现
- 联通的光纤--无线路由--mac过滤--存在问题
- android ActivityGroup认识