日期:2014-05-17  浏览次数:20365 次

电话面试题
C#
给你一个string字符串, abcd as,ccd.dsa
反转这个字符串变为: dsa.ccd,as abcd

要求:不能用【任何】【系统函数】。

------解决方案--------------------
加载到数组,从下标向上标读取.
------解决方案--------------------
从后往前遍历,组合呗
或者,将每个字符压栈,然后遍历栈,所以依次取出就翻转,比如

C# code

            string ss = "abcdefg";
            Stack<char> stack = new Stack<char>();
            foreach (char c in ss)
            {
                stack.Push(c);
            }
            ss = "";
            foreach (char c in stack)
            {
                ss += c.ToString();
            }
            MessageBox.Show(ss):
或者
            string ss = "abcdefg";
            string des = "";
            for(int i=ss.Length-1;i>=0;i--)
            {
                des += ss[i].ToString();
            }
            MessageBox.Show(des);

------解决方案--------------------
入栈出栈即可
------解决方案--------------------
探讨

你也没看题,不是全部反转。全部就简单了。

------解决方案--------------------
探讨
这种恶心的题目 直接用C 写算了
就算得到结果 其实实际中真没什么意义

------解决方案--------------------
C# code


            string oldStr = "abcd as,ccd.dsa";
            string cutStr = " ,.";
            string tempStr = "";
            string re = "";
            for (int i = oldStr .Length - 1; i >= 0 ;i-- )
            {
                char c = oldStr [i];
                bool iscut = false;
                foreach (char cut in cutStr)
                {
                    if(cut == c){iscut = true;continue;}
                }
                if(iscut){re = tempStr + c + re;tempStr = "";}
                else{tempStr = c + tempStr;}
            }
            return tempStr + re;

------解决方案--------------------
电话面试,别人主要看你的反应能力和解决问题的思路,面试者自己都不一定能写出来都是网上找的鬼题目。
------解决方案--------------------
希望这个可以帮到你:

C# code

private void Form1_Load(object sender, EventArgs e)
        {
            string[] aa = { "wo","ai","kan","mao","pian"};
            string temp = "";
            for (int i = 0; i < aa.Length / 2;i++)
            {
                temp = aa[aa.Length - i - 1];
                aa[aa.Length - i - 1] = aa[i];
                aa[i] = temp;
            }

            for (int j = 0; j < aa.Length; j++)
            {
                MessageBox.Show(aa[j]);
            }
//依次弹出:pian,mao,kan,ai,wo
 }

------解决方案--------------------
class stack:IStack
{
stack s;
stack next;
 
private string data;
public string Data
{
get { return data; }
set { data = value; }
}
public static int len = 0;
public void push(string data)
{
next = new stack();
next.data = data;
len++;
if (len > 0)
next.next = s;
else
{
s = new stack();
s.data = data;
}
s = next;
}
public string pop()
{
string str = s.data;
if(s.next!=null)
s = s.next;