# 华为校招软件上机考试题目解析

http://blog.csdn.net/gane_cheng/article/details/52184215

## 第一题 回文数字判断

import java.util.*;

public class Main
{
public static void main(String args[])
{
Scanner cin = new Scanner(System.in);
int a;
while (cin.hasNext())
{
a = cin.nextInt();
}
}

{
if (strIn == null || strIn.length() < 1)
{
return false;
}

char[] numArr = strIn.toCharArray();

for (int i = 0; i < numArr.length / 2; i++)
{
if (numArr[i] != numArr[numArr.length - 1 - i])
{
}
}

}
}

## 第二题 字符串排序


import java.util.*;

public class Main
{
public static void main(String args[])
{
Scanner cin = new Scanner(System.in);
String a;
while (cin.hasNext())
{
a = cin.next();
System.out.println(getAlphabetOrderString(a));
}
}

public static String getAlphabetOrderString(String strIn)
{
if (strIn == null || strIn.length() == 0)
{
return "";
}
char[] strArr = strIn.toCharArray();
int[] intArr = new int[58];

for (char c : strArr)
{
int tempNum = c - 'A';
if ((tempNum >= 0 && tempNum < 26) || (tempNum >= 32 && tempNum < 58))
{
intArr[c - 'A'] += 1;
}
}

int j = 0;

for (int i = 0; i < intArr.length; i++)
{
while (intArr[i] > 0)
{
while (j < strArr.length)
{
if (Character.isLetter(strArr[j]))
{
strArr[j++] = (char) (i + 'A');
intArr[i]--;
break;
}
else
{
j++;
}
}
}
}
return String.valueOf(strArr);
}
}

## 第三题 整数排序


import java.util.*;

public class Main
{
public static void main(String args[])
{
Scanner cin = new Scanner(System.in);
String a;
while (cin.hasNext())
{
a = cin.next();
String[] intStrArr = a.split(",");
int[] intArr = new int[intStrArr.length];
for (int i = 0; i < intArr.length; i++)
{
intArr[i] = Integer.parseInt(intStrArr[i]);
}

Arrays.sort(intArr);

if (intArr.length == 0)
{
System.out.println("");
}
else if (intArr.length == 1)
{
System.out.println(intArr[0]);
}
else if (intArr.length == 2 && intArr[0] == intArr[1])
{
System.out.println(intArr[0]);
}
else
{
System.out.print(intArr[0] + " ");

for (int i = 1; i < intArr.length - 1; i++)
{

if ((intArr[i] == intArr[i + 1] - 1) && intArr[i] == intArr[i - 1] + 1)
{
continue;
}

System.out.print(intArr[i] + " ");

}

System.out.print(intArr[intArr.length - 1]);
}

}
}

}