poj 1035

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、  若某个单词无论操作与否都无法在字典中找得到,则输出空

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值