微软中国经典算法题 求解(下周结帖)
面试时碰到的算法题 如下:
1:有一个随机字符串"BPMQKLNHZCY..."给定一个从A到Z之间的任意随机字符
如"N", 然后对随机字符串进行排序 从A到Z,比"N"小的放在"N"的左边 比 "N"大的放在"N"的右边,要求在排序的过程中不改变字符的相对位置,如示例字符串的"H"和"C" 在"N"后,在排序换到"N"前面时,也应保持"C"在"H"后的相对位置。
2:字符串 "{[(10+3)*18-24/8]*(48+37)}/3", 实现一个算法,求字符串算式的结果
3:{"peolpe":[
{"firstName":"Brett","lastName":"Mclaughlin","email":"aaa"},
{"firstName":"Jhon","lastName":"Hunter","email":"bbb"},
{"firstName":"Jason","lastName":"Harold","email":"ccc"},
]}
请实现一个算法,将上述json格式的数据填充到下面指定类的实例中
Public Class People{
Public String FirstName;
Public String LastName;
Public String Email;
}
[解决办法]
mark
[解决办法]
string s = @"{""people"":[
{""firstName"":""Brett"",""lastName"":""Mclaughlin"",""email"":""aaa""},
{""firstName"":""Jhon"",""lastName"":""Hunter"",""email"":""bbb""},
{""firstName"":""Jason"",""lastName"":""Harold"",""email"":""ccc""},]}";
MatchCollection matches = Regex.Matches(s, @"(?is)(?<={""people"":\[.*?){""firstName"":""(?<firstName>[^,]+)"",""lastName"":""(?<lastName>[^,]+)"",""email"":""(?<email>[^,]+)""},(?=.*?\]})");
List<People> peopleList = new List<People>();
foreach (Match match in matches)
{
People people = new People();
people.FirstName = match.Groups["firstName"].Value;
people.LastName = match.Groups["lastName"].Value;
people.Email = match.Groups["email"].Value;
peopleList.Add(people);
}
foreach (People people in peopleList)
Response.Write(string.Format("FirstName:{0}----LastName:{1}----Email:{2}<br/>", people.FirstName, people.LastName, people.Email));
public string test(string str_text, string str_index)
{
char[] arr = str_text.ToUpper().ToCharArray();
int index = Convert.ToChar(str_index.ToUpper());
string max = "";
string min = "";
for (int i = 0; i < arr.Length; i++)
{
if (arr[i] > index)
{
max += arr[i].ToString();
}
if (arr[i] < index)
{
min += arr[i].ToString();
}
}
return max + str_index.ToUpper() + min;
}
public string test(string str_text, string str_index)
{
char[] arr = str_text.ToUpper().ToCharArray();
int index = Convert.ToChar(str_index.ToUpper());
var big = arr.Where(x => x > index).Concat(str_index.ToUpper()).Concat(arr.Where(y => y < index)).ToList();
StringBuilder sb = new StringBuilder("");
foreach (char temp in big)
{
sb.Append(temp.ToString());
}
return sb.ToString();
}

string str = "MNJDOIkjaldfDVIUAASKFDFDFsdfsdegfdfgh";
StringBuilder sb1 = new StringBuilder();
StringBuilder sb2 = new StringBuilder();
foreach (char c in str)
{
if ((int)c < (int)'N')
{
sb1.Append(c);
}
else
{
sb2.Append(c);
}
}
str = sb1.ToString() + 'N' + sb2.ToString();