中文字幕在线一区二区在线,久久久精品免费观看国产,无码日日模日日碰夜夜爽,天堂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

      主站蜘蛛池模板: 国产精品久久无码免费看| 国产一区二区在线观看我不卡| 乌海市| mm在线精品视频| 久久综合给合久久97色| 久久精品成人免费观看97| 日本一区二区国产高清在线播放 | 国产日韩久久久久69影院| 国产熟女自拍视频网站| 99在线无码精品秘 入口九色| 亚洲蜜芽在线精品一区| 中文字幕有码高清| 日本成人一区二区不卡| 国产青青草久久亚洲精品| 精品久久久中文字幕二区| 堆龙德庆县| 午夜无码无遮挡在线视频| 91热爆在线精品| 亚洲无线码一区在线观看| 大肥婆老熟女一区二区精品| 日韩有码中文字幕国产| 蜜桃精品一区二区三区视频| 亚洲国产成人精品毛片九色| 康马县| 久久久调教亚洲| 久天啪天天久久99久孕妇| 99久久精品国产一区二区暴力| 亚洲AV无码一区二区水蜜桃 | 国产黄片一区视频在线观看| 芦山县| 盈江县| 亚洲精品国产二区三区在线 | 国产一起色一起爱| 国产主播一区二区在线观看 | 亚洲熟妇中文字幕五十av| 一级做a爱视频在线播放| 亚洲综合综合在线| 国产视频不卡在线| 中文字幕成人精品久久不卡| 青青草极品视频在线播放| 国产亚洲精选一区二区|