网易2016年Java工程师实习编程题目

题目描述:输入是一个16位数字的字符串,里面包括数字、字符,字符中如果包含‘9’或者‘g’,由于打印的时候,无法区分‘9’和‘g’,所以在使用时就需要查询,就需要把所有可能的情况检索出来。可能说的不清楚,打个比方就是,你输入9gxxxxxxxxxxxxxx,则检索的结果就是99xxxxxxxxxxxxxx,9gxxxxxxxxxxxxxx,g9xxxxxxxxxxxxxx,ggxxxxxxxxxxxxxx

package neteaseprograme;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class OutPutRsult {
	public static char[] baseChar = {'g','9'};  
	public static String[] strArray = {"9","g"};
	public static String[] resultStrArray = null;
	public static List<String> listTotal = new ArrayList<String>();
	public static int toalNumber = 1;
	public static void main(String[] args) {
		
		String str = "9999g99d9999999";
		List<Integer> list = new ArrayList<Integer>();
		char[] chStr = str.toCharArray();		
		
		for (int i = 0; i < chStr.length; i++) {
			if(chStr[i] == '9' || chStr[i] == 'g'){
				list.add(i);
			}
		}
		for (int j = 0; j < list.size(); j++) {
			toalNumber = toalNumber*2;
		}
		System.out.println("总的情况数:"+toalNumber);
		resultStrArray = new String[toalNumber];
		
		CreateString(strArray, baseChar);
		for (int i = 0; i < resultStrArray.length; i++) {
			char[] resultChar = resultStrArray[i].toCharArray();
			Iterator<Integer> it = list.iterator();
			int n = 0;
			char[] changeChar = str.toCharArray();
			while(it.hasNext()){				
				changeChar[it.next()] = resultChar[n];
				n++;
			}
			System.out.println(new String(changeChar));;
		}
		
		/*Iterator<String> itTotal = listTotal.iterator();
		while(itTotal.hasNext()){
			System.out.println(itTotal.next());
		}*/
	}

	public static String[] CreateString(String[] strArray,char[] baseStr) {
		
		String temp = null; 
		List<String> listStr = new ArrayList<String>();
		for (int i = 0; i < strArray.length; i++) {
			for (int j = 0; j < baseStr.length; j++) {
				temp = strArray[i]+baseStr[j];
				listStr.add(temp);
				listTotal.add(temp);
			}
		}
		Iterator<String> it = listStr.iterator();
		String[] newStrArray = new String[listStr.size()];
		System.out.println("新建数组长度"+newStrArray.length);
		int k = 0;
		while(it.hasNext()){
			newStrArray[k] = it.next();
			k++;
		}
		if(newStrArray.length == toalNumber){			
			resultStrArray = newStrArray;	
			return resultStrArray;	
		}
		return CreateString(newStrArray, baseStr);	
		
	}
}

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值