中文字幕在线一区二区在线,久久久精品免费观看国产,无码日日模日日碰夜夜爽,天堂av在线最新版在线,日韩美精品无码一本二本三本,麻豆精品三级国产国语,精品无码AⅤ片,国产区在线观看视频

      c 高級面試題目

      時間:2020-11-08 09:06:32 面試問題 我要投稿

      c 高級面試題目

      1、有一分?jǐn)?shù)序列:1/2,1/4,1/6,1/8„„,用函數(shù)調(diào)用的方法,求此數(shù)列前 20 項的和
      #include <stdio.h>
      double getValue()
      {
      double result = 0;
      int i = 2;
      while(i < 42)
      {
      result += 1.0 / i;//一定要使用 1.0 做除數(shù),不能用 1,否則結(jié)果將自動轉(zhuǎn)化成整數(shù),即 0.000000
      i += 2;
      }
      return result;
      }
      int main()
      {
      printf("result is %f\n", getValue());
      system("pause");
      return 0;
      }
      2、有一個數(shù)組 a[1000]存放 0--1000;要求每隔二個數(shù)刪掉一個數(shù),到末尾時循環(huán)至開頭繼續(xù)進(jìn)行,求最后一個被刪掉的數(shù)的原始下標(biāo)位置。
      以 7 個數(shù)為例:
      {0,1,2,3,4,5,6,7} 0-->1-->2(刪除)-->3-->4-->5(刪除)-->6-->7-->0(刪除),如此循環(huán)直到最后一個數(shù)被刪除。
      方法 1:數(shù)組
      #include <iostream>
      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;
      }方法 2:鏈表
      #include<iostream>
      using namespace std;
      #define null 0
      struct node
      {
      int data;
      node* next;
      };
      int main()
      {
      node* head=new node;
      head->data=0;
      head->next=null;
      node* p=head;
      for(int i=1;i<1000;i++)
      {
      node* tmp=new node;
      tmp->data=i;
      tmp->next=null;
      head->next=tmp;
      head=head->next;
      }
      head->next=p;
      while(p!=p->next)
      {
      p->next->next=p->next->next->next;
      p=p->next->next;
      }
      cout<<p->data;
      return 0;
      }
      方法 3:通用算法
      #include <stdio.h>
      #define MAXLINE 1000 //元素個數(shù)
      /*
      MAXLINE 元素個數(shù)
      a[] 元素數(shù)組
      R[] 指針場
      suffix 下標(biāo)
      index 返回最后的.下標(biāo)序號
      values 返回最后的下標(biāo)對應(yīng)的值
      start 從第幾個開始
      K 間隔
      */
      int find_n(int a[],int R[],int K,int& index,int& values,int s=0) {
      int suffix;
      int front_node,current_node;
      suffix=0;
      if(s==0) {
      current_node=0;
      front_node=MAXLINE-1;
      }
      else {
      current_node=s;
      front_node=s-1;
      }
      while(R[front_node]!=front_node) {
      printf("%d\n",a[current_node]);
      R[front_node]=R[current_node];
      if(K==1) {
      current_node=R[front_node];
      continue;
      }
      for(int i=0;i<K;i++){
      front_node=R[front_node];
      }
      current_node=R[front_node];
      }
      index=front_node;
      values=a[front_node];
      return 0;
      }
      int main(void) {
      int a[MAXLINE],R[MAXLINE],suffix,index,values,start,i,K;
      suffix=index=values=start=0;
      K=2;
      for(i=0;i<MAXLINE;i++) {
      a[i]=i;
      R[i]=i+1;
      }
      R[i-1]=0;
      find_n(a,R,K,index,values,2);
      printf("the value is %d,%d\n",index,values);
      return 0;
      }

      【c 高級面試題目】相關(guān)文章:

      C/C++面試題目11-21

      C C++面試筆試題目集錦11-15

      C++面試筆試題目11-21

      高級網(wǎng)管面試筆試題目11-16

      實用C++面試筆試題目11-21

      經(jīng)典c++面試筆試題目11-21

      Jr.C++/C#開發(fā)工程師面試筆試題目11-15

      經(jīng)典c++面試筆試題目22題11-21

      C++筆試題目分享11-22

      2016年華為認(rèn)證C/C++筆試題目11-06

      主站蜘蛛池模板: 对白刺激的老熟女露脸| 亚洲中出视频| 美女裸体无遮挡黄污网站| 亚洲午夜无码视频在线播放| 亚洲国产一区二区三区在线视频| 亚洲欧美日韩国产综合专区| 亚洲一区二区国产精品视频| 亚洲一区不卡在线导航| 中江县| 亚洲狠狠婷婷综合久久久| 色乱码一区二区三区在线| 国产亚洲精品久久麻豆| 亚洲人成18禁网站| 久久精品国产亚洲AV香蕉吃奶| 亚洲蜜桃av一区二区三区| 亚洲国产精品国自产拍av| 99久久精品久久久| 久久精品久久免费懂色| 国产360激情盗摄一区在线观看| 亚洲人成绝费网站色www| 日本一区二区在线视频免费观看| 泌阳县| 国产一级淫片免费大片| 国产青青草久久亚洲精品| 亚洲女同系列高清在线观看| 91情侣在线精品国产免费| 亚洲天堂日韩av在线综合| 国产精品日本天堂| 唐河县| 国产三级伦理视频在线| 亚洲精品中文字幕尤物综合| 国产成人精品aaaa视频一区| av手机在线天堂网| 国产精品国产三级国产av主| 麻豆国产AV网站| 91狼友在线观看免费完整版| 午夜国产精品视频在线| 二区三区国产在线观看| 亚洲中文字幕无码不卡电影| 国产自在自线午夜精品视频在| 佛学|