1. <tt id="5hhch"><source id="5hhch"></source></tt>
    1. <xmp id="5hhch"></xmp>

  2. <xmp id="5hhch"><rt id="5hhch"></rt></xmp>

    <rp id="5hhch"></rp>
        <dfn id="5hhch"></dfn>

      1. C筆試題

        時間:2023-04-05 00:32:28 筆試題目 我要投稿

        C筆試題

          1) 讀文件file1.txt的內(nèi)容(例如):

        C筆試題

          12

          34

          56

          輸出到file2.txt:

          56

          34

          12

          (逆序)

          2)輸出和為一個給定整數(shù)的所有組合

          例如n=5

          5=1+4;5=2+3(相加的數(shù)不能重復(fù))

          則輸出

          1,4;2,3。

          第一題,注意可增長數(shù)組的應(yīng)用.

          #include

          #include

          int main(void)

          { int MAX = 10;

          int *a = (int *)malloc(MAX * sizeof(int));

          int *b;

          FILE *fp1;

          FILE *fp2;

          fp1 = fopen(“a.txt”,”r”);

          if(fp1 == NULL)

          {printf(“error1″);

          exit(-1);

          }

          fp2 = fopen(“b.txt”,”w”);

          if(fp2 == NULL)

          {printf(“error2″);

          exit(-1);

          }

          int i = 0;

          int j = 0;

          while(fscanf(fp1,”%d”,&a[i]) != EOF)

          {i++;

          j++;

          if(i >= MAX)

          {

          MAX = 2 * MAX;

          b = (int*)realloc(a,MAX * sizeof(int));

          if(b == NULL)

          {printf(“error3″);

          exit(-1);

          }a = b;

          }}

          for(;–j >= 0;)

          fprintf(fp2,”%d\n”,a[j]);

          fclose(fp1);

          fclose(fp2);

          return 0;

          }

          第二題.

          #include

          int main(void)

          {unsigned long int i,j,k;

          printf(“please input the number\n”);

          scanf(“%d”,&i);

          if( i % 2 == 0)

          j = i / 2;

          else

          j = i / 2 + 1;

          printf(“The result is \n”);

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

          printf(“%d = %d + %d\n”,i,k,i – k);

          return 0;

          }

          #include

          void main()

          {unsigned long int a,i=1;

          scanf(“%d”,&a);

          if(a%2==0)

          { for(i=1;i printf(“%d”,a,a-i);

          }

          else

          for(i=1;i<=a/2;i++)

          printf(” %d, %d”,i,a-i);

          }

          兄弟,這樣的題目若是做不出來實在是有些不應(yīng)該, 給你一個遞規(guī)反向輸出字符串的例子,可謂是反序的經(jīng)典例程.

          void inverse(char *p)

          { if( *p = = ‘\0′ )

          return;

          inverse( p+1 );

          printf( “%c”, *p );

          }

          int main(int argc, char *argv[])

          {

          inverse(“abc\0″);

          return 0;

          }

          借簽了樓上的“遞規(guī)反向輸出”

          #include

          void test(FILE *fread, FILE *fwrite)

          { char buf[1024] = {0};

          if (!fgets(buf, sizeof(buf), fread))

          return;

          test( fread, fwrite );

          fputs(buf, fwrite);

          }

          int main(int argc, char *argv[])

          { FILE *fr = NULL;

          FILE *fw = NULL;

          fr = fopen(“data”, “rb”);

          fw = fopen(“dataout”, “wb”);

          test(fr, fw);

          fclose(fr);

          fclose(fw);

          return 0;

          }

          在對齊為4的情況下

          struct BBB

          { long num;

          char *name;

          short int data;

          char ha;

          short ba[5];

          }*p;

          p=0×1000000;

          p+0×200=____;

          (Ulong)p+0×200=____;

          (char*)p+0×200=____;

          解答:假設(shè)在32位CPU上,

          sizeof(long) = 4 bytes

          sizeof(char *) = 4 bytes

          sizeof(short int) = sizeof(short) = 2 bytes

          sizeof(char) = 1 bytes

          由于是4字節(jié)對齊,

          sizeof(struct BBB) = sizeof(*p)

          = 4 + 4 + 2 + 1 + 1/*補齊*/ + 2*5 + 2/*補齊*/ = 24 bytes (經(jīng)Dev-C++驗證)

          p=0×1000000;

          p+0×200=____;

          = 0×1000000 + 0×200*24

          (Ulong)p+0×200=____;

          = 0×1000000 + 0×200

          (char*)p+0×200=____;

          = 0×1000000 + 0×200*4

          你可以參考一下指針運算的細(xì)節(jié)

          寫一段程序,找出數(shù)組中第k大小的數(shù),輸出數(shù)所在的位置。例如{2,4,3,4,7}中,第一大的數(shù)是7,位置在4。第二大、第三大的數(shù)都是4,位置在 1、3隨便輸出哪一個均可。函數(shù)接口為:int find_orderk(const int* narry,const int n,const int k)

          要求算法復(fù)雜度不能是O(n^2)

          謝謝!

          可以先用快速排序進(jìn)行排序,其中用另外一個進(jìn)行地址查找

          代碼如下,在VC++6.0運行通過。給分吧^-^

          //快速排序

          #include

          usingnamespacestd;

          intPartition (int*L,intlow,int high)

          {inttemp = L[low];

          intpt = L[low];

          while (low < high)

          {while (low < high && L[high] >= pt)

          –high;

          L[low] = L[high];

          while (low < high && L[low] <= pt)

          ++low;

          L[low] = temp;

          }

          L[low] = temp;

          returnlow;

          }

          voidQSort (int*L,intlow,int high)

          {if (low < high)

          {

          intpl = Partition (L,low,high);

          QSort (L,low,pl – 1);

          QSort (L,pl + 1,high);

          }}

          intmain ()

          {intnarry[100],addr[100];

          intsum = 1,t;

          cout << “Input number:” << endl;

          cin >> t;

          while (t != -1)

          {narry[sum] = t;

          addr[sum - 1] = t;

          sum++;

          cin >> t;

          }

          sum -= 1;

          QSort (narry,1,sum);

          for (int i = 1; i <= sum;i++)

          cout << narry[i] << ‘\t’;

          cout << endl;

          intk;

          cout << “Please input place you want:” << endl;

          cin >> k;

          intaa = 1;

          intkk = 0;

          for (;;)

          {if (aa == k)

          break;

          if (narry[kk] != narry[kk + 1])

          {aa += 1;

          kk++;

          }

          }

          cout << “The NO.” << k << “number is:” << narry[sum - kk] << endl;

          cout << “And it’s place is:” ;

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

          {if (addr[i] == narry[sum - kk])

          cout << i << ‘\t’;

          }return0;

          }

          1、找錯

          Void test1()

          {

          char string[10];

          char* str1=”0123456789″;

          strcpy(string, str1);// 溢出,應(yīng)該包括一個存放’\0′的字符string[11]

          }

          Void test2()

          {

          char string[10], str1[10];

          for(I=0; I<10;I++)

          {str1[i] =’a';

          }

          strcpy(string, str1);// I,i沒有聲明。

          }

          Void test3(char* str1)

          {char string[10];

          if(strlen(str1)<=10)// 改成<10,字符溢出,將strlen改為sizeof也可以

          {strcpy(string, str1);

          }}

          2. void g(int**);

          int main()

          {int line[10],i;

          int *p=line; //p是地址的地址

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

          {*p=i;

          g(&p);//數(shù)組對應(yīng)的值加1

          }

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

          printf(“%d\n”,line[i]);

          return 0;

          }

          void g(int**p)

          { (**p)++;

          (*p)++;// 無效

          }

          輸出:

          1

          2

          3

          4

          5

          6

          7

          8

          9

          10

          3. 寫出程序運行結(jié)果

          int sum(int a)

          {auto int c=0;

          static int b=3;

          c+=1;

          b+=2;

          return(a+b+c);

          }

          void main()

          {int I;

          int a=2;

          for(I=0;I<5;I++)

          {printf(“%d,”, sum(a));

          }

          }

          // static會保存上次結(jié)果,記住這一點,剩下的自己寫

          輸出:8,10,12,14,16,

          4.

          int func(int a)

          {int b;

          switch(a)

          {case 1: 30;

          case 2: 20;

          case 3: 16;

          default: 0

          }

          return b;

          }

          則func(1)=?

          // b定義后就沒有賦值。

          5:

          int a[3];

          a[0]=0; a[1]=1; a[2]=2;

          int *p, *q;

          p=a;

          q=&a[2];

          則a[q-p]=a[2]

          解釋:指針一次移動一個int但計數(shù)為1

          今天早上的面試題9道,比較難,向牛人請教,國內(nèi)的一牛公司,坐落在北京北四環(huán)某大廈:

          1、線形表a、b為兩個有序升序的線形表,編寫一程序,使兩個有序線形表合并成一個有序升序線形表h;

          答案在 請化大學(xué) 嚴(yán)銳敏《數(shù)據(jù)結(jié)構(gòu)第二版》第二章例題,數(shù)據(jù)結(jié)構(gòu)當(dāng)中,這個叫做:兩路歸并排序

          Linklist *unio(Linklist *p,Linklist *q){

          linklist *R,*pa,*qa,*ra;

          pa=p;

          qa=q;

          R=ra=p;

          while(pa->next!=NULL&&qa->next!=NULL){

          if(pa->data>qa->data){

          ra->next=qa;

          qa=qa->next;

          }

          else{ra->next=pa;

          pa=pa->next;

          }}

          if(pa->next!=NULL)

          ra->next=pa;

          if(qa->next!=NULL)

          ra->next==qa;

          return R;

          }

          2、運用四色定理,為N個局域舉行配色,顏色為1、2、3、4四種,另有數(shù)組adj[][N],如adj[i][j]=1則表示i區(qū)域與j區(qū)域相鄰,數(shù)組color[N],如color[i]=1,表示i區(qū)域的顏色為1號顏色。

          四色填充

          3、用遞歸算法判斷數(shù)組a[N]是否為一個遞增數(shù)組。

          遞歸的方法,記錄當(dāng)前最大的,并且判斷當(dāng)前的是否比這個還大,大則繼續(xù),否則返回false結(jié)束:

          bool fun( int a[], int n )

          {

          if( n= =1 )

          return true;

          if( n= =2 )

          return a[n-1] >= a[n-2];

          return fun( a,n-1) && ( a[n-1] >= a[n-2] );

          }

          4、編寫算法,從10億個浮點數(shù)當(dāng)中,選出其中最大的10000個。

          1.給兩個數(shù)組和他們的大小,還有一動態(tài)開辟的內(nèi)存,求交集,把交集放到動態(tài)內(nèi)存dongtai,并且返回交集個數(shù)

          long jiaoji(long* a[],long b[],long* alength,long blength,long* dongtai[])

          2.單連表的建立,把’a'–’z’26個字母插入到連表中,并且倒敘,還要打印!

          方法1:

          typedef struct val

          { int date_1;

          struct val *next;

          }*p;

          void main(void)

          { char c;

          for(c=122;c>=97;c–)

          { p.date=c;

          p=p->next;

          }

          p.next=NULL;

          } }

          方法2:

          node *p = NULL;

          node *q = NULL;

          node *head = (node*)malloc(sizeof(node));

          head->data = ‘ ‘;head->next=NULL;

          node *first = (node*)malloc(sizeof(node));

          first->data = ‘a’;first->next=NULL;head->next = first;

          p = first;

          int longth = ‘z’ – ‘b’;

          int i=0;

          while ( i<=longth )

          {

          node *temp = (node*)malloc(sizeof(node));

          temp->data = ‘b’+i;temp->next=NULL;q=temp;

          head->next = temp; temp->next=p;p=q;

          i++;

          }

          print(head);

          3.可怕的題目終于來了

          象搜索的輸入信息是一個字符串,統(tǒng)計300萬輸入信息中的最熱門的前十條,我們每次輸入的一個字符串為不超過255byte,內(nèi)存使用只有1G,

          請描述思想,寫出算發(fā)(c語言),空間和時間復(fù)雜度,

          4.國內(nèi)的一些帖吧,如baidu,有幾十萬個主題,假設(shè)每一個主題都有上億的跟帖子,怎么樣設(shè)計這個系統(tǒng)速度最好,請描述思想,寫出算發(fā)(c語言),空間和時間復(fù)雜度,

          #include string.h

          main(void)

          { char *src=”hello,world”;

          char *dest=NULL;

          dest=(char *)malloc(strlen(src));

          int len=strlen(str);

          char *d=dest;

          char *s=src[len];

          while(len–!=0)

          d++=s–;

          printf(“%s”,dest);

          }

          找出錯誤!!

          #include “string.h”

          #include “stdio.h”

          #include “malloc.h”

          main(void)

          {

          char *src=”hello,world”;

          char *dest=NULL;

          dest=(char *)malloc(sizeof(char)*(strlen(src)+1));

          int len=strlen(src);

          char *d=dest;

          char *s=src+len-1;

          while(len–!=0)

          *d++=*s–;

          *d=’\0′;

          printf(“%s”,dest);

          }

          1. 簡述一個Linux驅(qū)動程序的主要流程與功能。

          2. 請列舉一個軟件中時間換空間或者空間換時間的例子。

          void swap(int a,int b)

          {

          int c; c=a;a=b;b=a;

          }

          —>空優(yōu)

          void swap(int a,int b)

          {

          a=a+b;b=a-b;a=a-b;

          }

          6. 請問一下程序?qū)⑤敵鍪裁唇Y(jié)果?

          char *RetMenory(void)

          { char p[] = “hellow world”;

          return p;

          }

          void Test(void)

          { char *str = NULL;

          str = RetMemory();

          printf(str);

          }

          RetMenory執(zhí)行完畢,p資源被回收,指向未知地址。返回地址,str的內(nèi)容應(yīng)是不可預(yù)測的, 打印的應(yīng)該是str的地址

          寫一個函數(shù),它的原形是int continumax(char *outputstr,char *intputstr)

          功能:

          在字符串中找出連續(xù)最長的數(shù)字串,并把這個串的長度返回,并把這個最長數(shù)字串付給其中一個函數(shù)參數(shù)outputstr所指內(nèi)存。例如:”abcd12345ed125ss123456789″的首地址傳給intputstr后,函數(shù)將返回

          9,outputstr所指的值為123456789

          int continumax(char *outputstr, char *inputstr)

          {char *in = inputstr, *out = outputstr, *temp, *final;

          int count = 0, maxlen = 0;

          while( *in != ‘\0′ )

          {if( *in > 47 && *in < 58 )

          {for(temp = in; *in > 47 && *in < 58 ; in++ )

          count++;

          }

          else

          in++;

          if( maxlen < count )

          {maxlen = count;

          count = 0;

          final = temp;

          }}

          for(int i = 0; i < maxlen; i++)

          {*out = *final;

          out++;

          final++;

          }

          *out = ‘\0′;

          return maxlen;

          }

        【C筆試題】相關(guān)文章:

        C/C++程序員必備資料 常見筆面試題深入解析12-12

        C#筆試題02-24

        C++筆試題03-25

        C++ 筆試題08-09

        基礎(chǔ)C++/C語言筆試題分享11-21

        華為C語言筆試題12-12

        Sony C++筆試題02-11

        雅虎C#筆試題03-07

        常規(guī)的C程序筆試題12-09

        華為筆試題(C語言)12-10

        国产高潮无套免费视频_久久九九兔免费精品6_99精品热6080YY久久_国产91久久久久久无码

        1. <tt id="5hhch"><source id="5hhch"></source></tt>
          1. <xmp id="5hhch"></xmp>

        2. <xmp id="5hhch"><rt id="5hhch"></rt></xmp>

          <rp id="5hhch"></rp>
              <dfn id="5hhch"></dfn>