日期:2014-05-17 浏览次数:20385 次
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);
------解决方案--------------------
入栈出栈即可
------解决方案--------------------
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;
------解决方案--------------------
电话面试,别人主要看你的反应能力和解决问题的思路,面试者自己都不一定能写出来都是网上找的鬼题目。
------解决方案--------------------
希望这个可以帮到你:
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;