主要是这次面试来的太突然,春节面的试,似乎是上海微创。一面被刷下去,英文差评。下文两道题,一个给了样例,依据没说,另一个是链表的翻转和移除,当时的情况是,我没带电脑回家,用的在线编译器。谁用谁知道。
using System;
public class Test{
//测试样例
/*
ABCBEF => B
ADECBA => A
FEDDBB => D
f(x)=>y
*/
public static int count = 6;
public static char dealfx(string test)
{
for(int i=0;i<count/2;i++)
for(int j=count/2;j<count;j++)
{
if( test[i]== test[j])
{
return test[i];
}
}
return '@';
}
public static void Main()
{
string testS1="ABCBEF";
string testS2="ADECBA";
string testS3="FEDDBB";
Console.WriteLine(testS1+":"+(dealfx(testS1)!='@'?dealfx(testS1):'0'));
Console.WriteLine(testS2+":"+(dealfx(testS2)!='@'?dealfx(testS2):'0'));
Console.WriteLine(testS3+":"+(dealfx(testS3)!='@'?dealfx(testS3):'0'));
Console.WriteLine("ABCDEF:"+(dealfx("ABCDEF")!='@'?dealfx("ABCDEF"):'0'));
}
}
Q2
using System;
public class Test
{
public class LinkNode
{
public LinkNode Next;
public int value;
};
public static void giveNum(LinkNode l)
{
for(int i=1;i<10;i++)
{
LinkNode lTest=new LinkNode();
l.value=i;
l.Next=lTest;
if(i<9)
{
l=lTest;
}
}
l.Next=null;
}
public static LinkNode Remove(int value,LinkNode head)
{
LinkNode p=new LinkNode();
LinkNode pHead=new LinkNode();
LinkNode q;
pHead=p;
while(head!=null)
{
if(head.value==value)
{
head=head.Next;
continue;
}
else
{
q=new LinkNode();
if(head.Next==null)
{
q=null;
}
p.Next=q;
p.value=head.value;
p=q;
}
head=head.Next;
}
return pHead;
}
public static LinkNode Reverse(LinkNode head)
{
LinkNode p=new LinkNode();
LinkNode q;
q=new LinkNode();
q.value=head.value;
q.Next=null;
p=q;
head=head.Next;
while(head!=null)
{
q=new LinkNode();
q.value=head.value;
q.Next=p;
p=q;
head=head.Next;
}
return p;
}
public static void show(LinkNode l)
{
while(l!=null)
{
Console.Write(l.value+" ");
l=l.Next;
}
Console.WriteLine();
}
public static void Main()
{
LinkNode head=new LinkNode();
giveNum(head);
Console.WriteLine("---------List Content---------");
show(head);
Console.WriteLine("-------------------------");
Console.WriteLine("------Remove 3------");
Console.WriteLine("-------------------------");
LinkNode remove= Remove(3,head);
show(remove);
Console.WriteLine("--------------------------");
Console.WriteLine("------Reverse list-----");
Console.WriteLine("--------------------------");
LinkNode lastTest=Reverse(head);
show(lastTest);
}
}