67,515
社区成员
发帖
与我相关
我的任务
分享
public static void main(String [] args) {
dealUrl("www。qΒ5。c Om");
}
private static void dealUrl(String url) {
char[] ac = url.toLowerCase().toCharArray();
List<List<String>> charList = new ArrayList<List<String>>();
List<String> tempList = null;
for (int i = 0; i < ac.length; i++) {
tempList = new ArrayList<String>();
int charIntValue = (int) ac[i];
if (Character.isDigit(ac[i])) {//数字
tempList.add(ac[i]+"");
} else if (charIntValue == 46 ||charIntValue == 65294 ){ //点
tempList.add(((char) 46)+"");//半角点
tempList.add(((char) 65294)+"");//全角点
tempList.add("。");//句号
} else if (charIntValue == 79 || charIntValue == 65359
|| charIntValue == 111 || charIntValue == 65327){//字母o
tempList.add(((char) 79)+"");//半角o
tempList.add(((char) 65359)+"");//全角o
tempList.add(((char) 111)+"");//半角大写o
tempList.add(((char) 65327)+"");//全角大写o
tempList.add("0");//零
} else if(charIntValue == 12288 || charIntValue == 32) {//空格
tempList.add(((char) 32)+"");//半角空格
tempList.add(((char) 12288)+"");//全角空格
} else if (charIntValue >= 65281 && charIntValue <= 65374) {//全角
char n = (char) (charIntValue - 65248);
tempList.add(ac[i]+"");//全角字符
tempList.add(n+"");//半角字符
tempList.add((ac[i]+"").toUpperCase());//全角大写
tempList.add((n+"").toUpperCase());//半角大写
} else {
char n = (char) (65248+charIntValue);
tempList.add(ac[i]+"");//半角字符
tempList.add(n+"");//全角字符
tempList.add((ac[i]+"").toUpperCase());//半角大写
tempList.add((n+"").toUpperCase());//全角大写
}
charList.add(tempList);
}
//分组处理
List<List<String>> partChongZuList = new ArrayList<List<String>>();
List<List<String>> partList = null;
int allSize = charList.size();
int fenGe = 4;
int partCount = allSize/fenGe;
if (partCount > 0 ) {
for (int i = 0; i < allSize/fenGe; i++) {
int tempSize = fenGe*(i+1);
if(allSize/tempSize == 1) {
tempSize = allSize;
}
partList = new ArrayList<List<String>>();
for (int k = i*fenGe; k < tempSize; k++) {
partList.add(charList.get(k));
}
partChongZuList .add(chongZu(partList));
}
List<String> aa = chongZu(partChongZuList);
System.out.println(aa.size());
} else {
List<String> aa = chongZu(charList);
System.out.println(aa.size());
}
}
/**
* 重组网址
* @param charList
*/
private static List<String> chongZu(List<List<String>> charList){
List<String> newStr = new ArrayList<String>();
List<String> tempStr = new ArrayList<String>();
int allLn = charList.size();
for (int i = 0; i < allLn; i++) {
List<String> t = charList.get(i);
int tSize = t.size();
for (int j = 0; j < tSize; j++) {
if (i == 0) {
tempStr.add( t.get(j));
} else {
String ns = "";
int nSize = newStr.size();
for (int k = 0 ; k < nSize; k++) {
ns = newStr.get(k);
ns += t.get(j);
tempStr.add(ns);
}
}
}
newStr.clear();
newStr.addAll(tempStr);
tempStr.clear();
System.out.println(newStr.size());
}
return newStr;
}
public static void main(String [] args) {
dealUrl("www。qΒ5。c Om");
}
private static void dealUrl(String url) {
//把网址转化为小写并拆分成单个字符数组
char[] ac = url.toLowerCase().toCharArray();
List<List<String>> charList = new ArrayList<List<String>>();
//存放网址中每个字符可能出现的情况
List<String> tempList = null;
for (int i = 0; i < ac.length; i++) {
tempList = new ArrayList<String>();
int charIntValue = (int) ac[i];
if (Character.isDigit(ac[i])) {//数字
tempList.add(ac[i]+"");
} else if (charIntValue == 46 ||charIntValue == 65294 ){ //点
tempList.add(((char) 46)+"");//半角点
tempList.add(((char) 65294)+"");//全角点
tempList.add("。");//句号
} else if (charIntValue == 79 || charIntValue == 65359
|| charIntValue == 111 || charIntValue == 65327){//字母o
tempList.add(((char) 79)+"");//半角o
tempList.add(((char) 65359)+"");//全角o
tempList.add(((char) 111)+"");//半角大写o
tempList.add(((char) 65327)+"");//全角大写o
tempList.add("0");//零
} else if(charIntValue == 12288 || charIntValue == 32) {//空格
tempList.add(((char) 32)+"");//半角空格
tempList.add(((char) 12288)+"");//全角空格
} else if (charIntValue >= 65281 && charIntValue <= 65374) {//全角
char n = (char) (charIntValue - 65248);
tempList.add(ac[i]+"");//全角字符
tempList.add(n+"");//半角字符
tempList.add((ac[i]+"").toUpperCase());//全角大写
tempList.add((n+"").toUpperCase());//半角大写
} else {
char n = (char) (65248+charIntValue);
tempList.add(ac[i]+"");//半角字符
tempList.add(n+"");//全角字符
tempList.add((ac[i]+"").toUpperCase());//半角大写
tempList.add((n+"").toUpperCase());//全角大写
}
charList.add(tempList);
}
//分组处理
List<List<String>> partChongZuList = new ArrayList<List<String>>();
List<List<String>> partList = null;
int allSize = charList.size();
int fenGe = 4;//按每4个字符一组
int partCount = allSize/fenGe;
if (partCount > 0 ) {
for (int i = 0; i < allSize/fenGe; i++) {
int tempSize = fenGe*(i+1);
//如果allSize/tempSize == 1,剩下的字符集合为一组
if(allSize/tempSize == 1) {
tempSize = allSize;
}
partList = new ArrayList<List<String>>();
for (int k = i*fenGe; k < tempSize; k++) {
partList.add(charList.get(k));
}
//重组部分字符集合,并准备下次重组,eg:www。、 WWW.
partChongZuList .add(chongZu(partList));
}
//重组分组完成后的
List<String> aa = chongZu(partChongZuList);
System.out.println(aa.size());
} else {
List<String> aa = chongZu(charList);
System.out.println(aa.size());
}
}
/**
* 重组网址
* @param charList
*/
private static List<String> chongZu(List<List<String>> charList){
List<String> newStr = new ArrayList<String>();
List<String> tempStr = new ArrayList<String>();
int allLn = charList.size();
for (int i = 0; i < allLn; i++) {
//获取字符集合
List<String> t = charList.get(i);
int tSize = t.size();
for (int j = 0; j < tSize; j++) {
//外层第一次循环,只需把字符放到tempStr集合中即可
if (i == 0) {
tempStr.add( t.get(j));
} else {
String ns = "";
//上次重组后集合的长度
int nSize = newStr.size();
for (int k = 0 ; k < nSize; k++) {
ns = newStr.get(k);
//循环累加本次要重组的字符
ns += t.get(j);
//存放重组后的字符串
tempStr.add(ns);
}
}
}
newStr.clear();
newStr.addAll(tempStr);
tempStr.clear();
System.out.println(newStr.size());
}
return newStr;
}