最近面试遇到的关于字符串的输出查找题目

/// <summary>
/// 输出第一个只出现一次的字母
/// </summary>
private static void OutPutTheFirstLetter()
{
string a = Console.ReadLine();
byte[] array = System.Text.Encoding.ASCII.GetBytes(a);
int b = -1;
for (int i = 0; i < array.Length; i++)
{
for (int j = i + 1; j < array.Length; j++)
{
if (array[i].ToString() == array[j].ToString())
{
b
= i;
goto Found;


}
}
}
Found:
if (b == -1)
{
Console.WriteLine(
"未找到");
Console.ReadKey();
}
else
{
Console.WriteLine(System.Text.Encoding.ASCII.GetString(array, b,
1));
Console.ReadKey();
}

}
/// <summary>
/// 输入字符串 倒序输出
/// </summary>
private static void OutPutDesc()
{
string a = Console.ReadLine();

byte[] array = System.Text.Encoding.ASCII.GetBytes(a);
byte[] arr2 = new byte[array.Length];
for (int i = 0; i < array.Length; i++)
{
arr2[i]
= array[array.Length - i - 1];
}
Console.WriteLine(System.Text.Encoding.ASCII.GetString(arr2));
Console.ReadKey();
}

posted on 2011-04-11 12:52  幽幽南山下  阅读(292)  评论(0编辑  收藏  举报

导航