1、排序一个有大小字符,数字组成的字符串,例如EBa37-->37BEa
string inputs = "EBa37";
char[] result = inputs.ToCharArray();
char copyInputs;
for (int i = 0; i < result.Length - 1; i++)
{
for (int j = i; j < result.Length; j++)
{
if (result[i] > result[j])
{
copyInputs = result[j];
result[j] = result[i];
result[i] = copyInputs;
}
}
}
}
2、判断一个输入是不是水仙花状,如66566,2b22b2是,123321k不是
string inputs = "123321k";
int stringLength = inputs.Length;
bool isFlower = true;
for (int i = 0; i < stringLength / 2; i++)
{
if (inputs[i] != inputs[stringLength - i - 1])
{
isFlower = false;
break;
}
}
3、转换2进制、8进制、16进制表示的数字转换成为Decimal类型,任意选用语言,不得使用语言内部实现的类型转换函数/方法
如果使用.NET提供的转换则:Console.Write(Convert.ToInt32("101", 8));
static void ConvertType(string value, int type)
{
double currentType = Convert.ToDouble(type.ToString());
decimal hello = 0;
int powIndex = -1;
for (int i = value.Length - 1; i >= 0; i--)
{
powIndex++;
if (Convert.ToDouble(value[i].ToString()) != 0)
{
hello += (decimal)System.Math.Pow(currentType, powIndex);
}
}
Console.Write(hello);
}
4、把一个数组中的重复元素挑出来然后并到数组尾部
(1)把重复的放到数组尾部
string stringInputs = "benqbqcbqs";
char[] userChar = stringInputs.ToCharArray();
List<string> list = new List<string>();
StringBuilder sbRepeateObject = new StringBuilder(userChar.Length);
string userObject = "";
for (int i = 0; i < userChar.Length; i++)
{
userObject = userChar[i].ToString();
if (!list.Contains(userObject))
{
list.Add(userObject);
}
else
{
sbRepeateObject.Append(userObject.ToString());
}
}
list.Add(sbRepeateObject.ToString());
(2)把所有重复的字符都放至数组尾部
string stringInputs = "benqbqcbqs";
string repeatString = "";
string originString = "";
string currentString = "";
for (int i = 0; i < stringInputs.Length; i++)
{
currentString = stringInputs[i].ToString();
if (Regex.Matches(stringInputs, currentString).Count == 1)
{
originString += currentString;
}
else
{
repeatString += currentString;
}
}
Console.WriteLine(originString + repeatString);