H3C 笔试经历

代码
笔试是在6号的早上,理工主楼进行的,还是比较简单的,13道选择题,两道程序题,还有一些附加题,在此贴出两道程序题的题目:
     
1、将一个链表进行反序;
     
2、有一个数组a[1000]存放0--999;要求每隔二个数删掉一个数,到末尾时循环至开头继续进行,求最后一个被删掉的数的原始下标位置。以7个数为例:{0,1,2,3,4,5,6,70-->1-->2(删除)-->3-->4-->5(删除)-->6-->7-->0(删除),如此循环直到最后一个数被删除。
typedef 
struct linknode
{
int data;
struct linknode *next;
}node;
//将一个链表逆置
node *reverse(node *head)
{
node 
*p,*q,*r;
p
=head;
q
=p->next;
while(q!=NULL)
{
r
=q->next;
q
->next=p;
p
=q;
q
=r;
}
head
->next=NULL;
head
=p;
return head;
}
第二题的答案,这是我在网上找的一个,我当时是用另一种方法做的,觉得还可以,有空的时候给大家贴出来看看
#include 
<iostream.h>
using namespace std;
#define null 1000
int main()
{
int arr[1000];
for (int i=0;i<1000;++i)
arr[i]
=i;
int j=0;
int count=0;
while(count<999)
{
while(arr[j%1000]==null)
j
=(++j)%1000;
j
=(++j)%1000;
while(arr[j%1000]==null)
j
=(++j)%1000;
j
=(++j)%1000;
while(arr[j%1000]==null)
j
=(++j)%1000;
arr[j]
=null;
++count;
}
while(arr[j]==null)
j
=(++j)%1000;
cout
<<J<<ENDL;
return 0;
}

原文地址:https://www.cnblogs.com/alamps/p/1686649.html