`
longxingtx520
  • 浏览: 17867 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
最近访客 更多访客>>
社区版块
存档分类
最新评论

算法题

阅读更多

package cn.longxingtx.number;

public class Number {
	
	private void strNumber(String[] str_array, String str, String c) {
		String str_new;
		String c_new;
		for(int i=0; i<str_array.length; i++) {		
			str_new = str;
			if(str_new.length() == 2 && str_array[i].equals("4")) {
				continue;
			}
			if(str_new.indexOf(str_array[i]) != -1) {
				continue;
			}
			if(c.equals("3") && str_array[i].equals("5")) {
				continue;
			}
			if(c.equals("5") && str_array[i].equals("3")) {
				continue;
			}
			str_new += str_array[i];
			c_new = str_array[i];
			if(str_new.length() == 5) {
				System.out.println(str_new.replace("a", "2"));
				return;
			}
			strNumber(str_array, str_new, c_new);
		}
	}
	
	/**
	 * @parai args
	 */
	public static void main(String[] args) {
		Number number = new Number();
		String c ="";
		String[] str_array = {"1", "2", "a", "3", "4", "5"};
		String str = "";
		number.strNumber(str_array, str, c);
	}

}
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics