某公司上機題

來源:互聯網
上載者:User


        前幾天出去面試,筆試和面試後,技術主管給出了道上機題:六個數,要一直按由小到大的順序排列,可以隨意的添加和刪除。。。

        對於這個公司的面試這裡不想多說什麼,只分享下技術。


     程式是以很簡單的方式做出來的,其中並未考慮執行效率問題,上機題嘛,弄出個結果就很好了

#include<stdio.h>

#include<string.h>

int num[6];

void add(int n)

{

int i,post=0;

int k;

while((n>num[post])&&(post<6))

post++;

for(i=0;i<post;i++)

{

    num[i]=num[i+1];

}

num[post-1]=n;

for(k=0;k<6;k++)

printf("%d ",num[k]);

printf("\n");

}

void del(int n)

{

int i;

int k;

int post=n;

for(i=post-1;i>0;i--)

{

    num[i]=num[i-1];

}

num[0]=0;

for(k=0;k<6;k++)

printf("%d ",num[k]);

printf("\n");

}

void ret()

{

int i,k;

for(i=0;i<6;i++)

num[i]=0;

for(k=0;k<6;k++)

printf("%d ",num[k]);

printf("\n");

}

main()

{

int n,i;

char chr;

for(i=0;i<6;i++)

num[i]=0;

for(i=0;i<6;i++)

printf("%d ",num[i]);

printf("\n");

while(1)

{

scanf("%c,%d",&chr,&n);

if(chr=='A')

add(n);

else if(chr=='D')

del(n);

else if(chr=='R')

ret();

}

}

運行結果如下:


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.