華為認(rèn)證上機(jī)考試題

    時(shí)間:2024-08-24 13:06:26 華為認(rèn)證 我要投稿
    • 相關(guān)推薦

    2016年華為認(rèn)證上機(jī)考試題

      華為認(rèn)證是計(jì)算機(jī)網(wǎng)絡(luò)專業(yè)的一個(gè)重要認(rèn)證,下面yjbys小編為各位同學(xué)們提供最新的華為認(rèn)證考試題及答案,希望對大家考試復(fù)習(xí)有所幫助!

    2016年華為認(rèn)證上機(jī)考試題

      1.輸入整型數(shù)組求數(shù)組的最小數(shù)和最大數(shù)之和,例如輸入1,2,3,4則輸出為5,當(dāng)輸入只有一個(gè)數(shù)的時(shí)候,則最小數(shù)和最大數(shù)都是該數(shù),例如只輸入1,則輸出為2;另外數(shù)組的長度不超過50

      #include

      main()

      {

      intnum[50]={0};

      inti,n;

      printf("請輸入整型數(shù)組的長度(1~50):");

      scanf("%d",&n);

      printf("請輸入整型數(shù)組的元素:");

      for(i=0;i

      {

      scanf("%d",&num[i]);

      }

      intmin_num=num[0];

      intmax_num=num[0];

      for(intj=0;j

      {

      if(max_num

      max_num=num[j];

      elseif(min_num>num[j])

      min_num=num[j];

      }

      intsum=min_num+max_num;

      printf("數(shù)組中最大與最小值之和:%d\n",sum);

      return0;

      }

      2.求兩個(gè)長長整型的數(shù)據(jù)的和并輸出,例如輸入1233333333333333。。。 3111111111111111111111111.。。。,則輸出。。。。

      #include

      #include

      #include

      main()

      {

      char*num1,*num2; //兩個(gè)長長整型數(shù)據(jù)

      char*sum;

      // inttemp;

      int len_num1,len_num2; // 兩個(gè)長長整型數(shù)據(jù)的長度

      intlen_max,len_min;

      num1=(char*)malloc(sizeof(char));

      num2=(char*)malloc(sizeof(char));

      printf("輸入兩個(gè)長長整型數(shù)據(jù):");

      scanf("%s",num1);

      printf("輸入兩個(gè)長長整型數(shù)據(jù):");

      scanf("%s",num2);

      len_num1=strlen(num1);

      len_num2=strlen(num2);

      len_max=(len_num1>=len_num2)?len_num1:len_num2;

      len_min=(len_num1<=len_num2)?len_num1:len_num2;

      int len_max1=len_max;

      sum=(char*)malloc(sizeof(char)*len_max);

      memset(sum,0x00,len_max+1);//切忌初始化

      for(;len_num1>0&&len_num2>0;len_num1--,len_num2--)

      {

      sum[len_max--]=((num1[len_num1-1]-'0')+(num2[len_num2-1]-'0'));

      }

      if(len_num1>0)

      {

      sum[len_max--]=num1[len_num1- 1 ]-'0';

      len_num1--;

      }

      if(len_num2>0)

      {

      sum[len_max--]=num1[len_num2- 1]-'0';

      len_num2--;

      }

      for(intj=len_max1;j>=0;j--) //實(shí)現(xiàn)進(jìn)位操作

      {

      // temp=sum[j]-'0';

      if(sum[j]>=10)

      {

      sum[j-1]+=sum[j]/10;

      sum[j]%=10;

      }

      }

      char*outsum=(char*)malloc(sizeof(char)*len_max1);

      j=0;

      while(sum[j]==0) //跳出頭部0元素

      j++;

      for(int m=0;m

      outsum[m]=sum[j]+'0';

      outsum[m]='\0';

      printf("輸出兩長長整型數(shù)據(jù)之和:%s\n",outsum);

      return0;

      }

      3.通過鍵盤輸入一串小寫字母(a~z)組成的字符串。請編寫一個(gè)字符串過濾程序,若字符串中出現(xiàn)多個(gè)相同的字符,將非首次出現(xiàn)的字符過濾掉。

      比如字符串“abacacde”過濾結(jié)果為“abcde”。

      要求實(shí)現(xiàn)函數(shù):

      void stringFilter(const char *pInputStr,long lInputLen, char *pOutputStr);

      【輸入】 pInputStr:輸入字符串

      lInputLen: 輸入字符串長度

      【輸出】 pOutputStr:輸出字符串,空間已經(jīng)開辟好,與輸入字符串等長;

      #include

      #include

      #include

      void stringFilter(const char *p_str, longlen, char *p_outstr)

      {

      intarray[256]={0};

      const char *tmp = p_str;

      for(int j=0;j

      {

      if(array[tmp[j]]==0)

      *p_outstr++=tmp[j];

      array[tmp[j]]++;

      }

      *p_outstr= '\0';

      }

      void main()

      {

      char *str = "cccddecc";

      intlen = strlen(str);

      char* outstr = (char *)malloc(len*sizeof(char));

      stringFilter(str,len,outstr);

      printf("%s\n",outstr);

      free(outstr);

      outstr= NULL;

      }

      4.通過鍵盤輸入一串小寫字母(a~z)組成的字符串。請編寫一個(gè)字符串壓縮程序,將字符串中連續(xù)出席的重復(fù)字母進(jìn)行壓縮,并輸出壓縮后的字符串。

      壓縮規(guī)則:

      1. 僅壓縮連續(xù)重復(fù)出現(xiàn)的字符。比如字符串"abcbc"由于無連續(xù)重復(fù)字符,壓縮后的字符串還是"abcbc".

      2. 壓縮字段的格式為"字符重復(fù)的次數(shù)+字符"。例如:字符串"xxxyyyyyyz"壓縮后就成為"3x6yz"

      要求實(shí)現(xiàn)函數(shù):

      void stringZip(const char*pInputStr, long lInputLen, char *pOutputStr);

      【輸入】 pInputStr: 輸入字符串

      lInputLen: 輸入字符串長度

      【輸出】 pOutputStr: 輸出字符串,空間已經(jīng)開辟好,與輸入字符串等長;

      #include

      #include

      #include

      void stringZip(const char *p_str, long len,char *p_outstr)

      {

      intcount=1;

      for(inti=0;i

      {

      if(p_str[i]==p_str[i+1])

      {

      count++;

      }

      else

      {

      if(count>1)

      {

      *p_outstr++= count +'0';

      *p_outstr++=p_str[i];

      }

      else

      {

      *p_outstr++=p_str[i];

      }

      count = 1;//注意其位置

      }

      }

      *p_outstr= '\0';

      }

      void main()

      {

      char*str = "cccddecc";

      printf("壓縮之前的字符串為:%s\n",str);

      intlen = strlen(str);

      char* outstr = (char*)malloc(len*sizeof(char));

      stringZip(str,len,outstr);

      printf("壓縮之后的字符串為:%s\n",outstr);

      free(outstr);

      outstr= NULL;

      }

      5.通過鍵盤輸入100以內(nèi)正整數(shù)的加、減運(yùn)算式,請編寫一個(gè)程序輸出運(yùn)算結(jié)果字符串。

      輸入字符串的格式為:“操作數(shù)1 運(yùn)算符 操作數(shù)2”,“操作數(shù)”與“運(yùn)算符”之間以一個(gè)空格隔開。

      補(bǔ)充說明:

      1. 操作數(shù)為正整數(shù),不需要考慮計(jì)算結(jié)果溢出的情況。

      2. 若輸入算式格式錯(cuò)誤,輸出結(jié)果為“0”。

      要求實(shí)現(xiàn)函數(shù):

      void arithmetic(const char*pInputStr, long lInputLen, char *pOutputStr);

      【輸入】 pInputStr: 輸入字符串

      lInputLen: 輸入字符串長度

      【輸出】 pOutputStr: 輸出字符串,空間已經(jīng)開辟好,與輸入字符串等長;

      #include

      #include

      #include

      void arithmetic(const char *input, longlen, char *output)

      {

      chars1[10];

      chars2[10];

      chars3[10];

      intcnt = 0;

      intlen_input=strlen(input);

      for(inti=0;i

      {

      if(input[i]=='')

      cnt++;

      }

      if(cnt!=2)

      {

      *output++= '0';

      *output= '\0';

      return;

      }

      sscanf(input,"%s %s %s",s1,s2,s3);

      if(strlen(s2)!=1||(s2[0]!='+'&&s2[0]!='-'))

      {

      *output++= '0';

      *output= '\0';

      return;

      }

      int len_s1=strlen(s1);

      for(i=0;i

      {

      if(s1[i]<'0'||s1[i]>'9')

      {

      *output++= '0';

      *output= '\0';

      return;

      }

      }

      intlen_s3=strlen(s3);

      for(i=0;i

      {

      if(s3[i]<'0'||s3[i]>'9')

      {

      *output++= '0';

      *output= '\0';

      return;

      }

      }

      int x = atoi(s1);

      int y = atoi(s3);

      if(s2[0]=='+')

      {

      intresult = x+y;

      itoa(result,output,10);

      }

      elseif(s2[0]=='-')

      {

      intresult = x-y;

      itoa(result,output,10);

      }

      else

      {

      *output++= '0';

      *output= '\0';

      return;

      }

      }

      void main()

      {

      charstr[] = {"10 - 23"};

      charoutstr[10];

      intlen = strlen(str);

      arithmetic(str,len,outstr);

      printf("%s\n",str);

      printf("%s\n",outstr);

      }

      6.一組人(n個(gè)),圍成一圈,從某人開始數(shù)到第三個(gè)的人出列,再接著從下一個(gè)人開始數(shù),最終輸出最終出列的人

      (約瑟夫環(huán)是一個(gè)數(shù)學(xué)的應(yīng)用問題:已知n個(gè)人(以編號1,2,3...n分別表示)圍坐在一張圓桌周圍。從編號為k的人開始報(bào)數(shù),數(shù)到m的那個(gè)人出列;他的下一個(gè)人又從1開始報(bào)數(shù),數(shù)到m的那個(gè)人又出列;依此規(guī)律重復(fù)下去,直到圓桌周圍的人全部出列。)

      #include

      #include

      #include

      #include

      typedef struct Node

      {

      intdata;

      structNode *next;

      }LinkList;

      LinkList *create(int n)

      {

      LinkList*p,*q,*head;

      inti=1;

      p=(LinkList*)malloc(sizeof(LinkList));

      p->data=i;

      head=p;

      for(i=1;i<=n;i++)

      {

      q=(LinkList*)malloc(sizeof(LinkList));

      q->data=i+1;

      p->next=q;

      p=q;

      }

      p->next=head; //使鏈表尾連接鏈表頭,形成循環(huán)鏈表

      returnhead;

      free(p);

      p=NULL;

      free(q);

      q=NULL;

      }

      void deletefun(LinkList *L,int m)

      {

      LinkList*p,*q,*temp;

      inti;

      p=L;

      while(p->next!=p)

      {

      for(i=1;i

      {

      q=p;

      p=p->next;

      }

      printf("%5d",p->data);

      temp=p;

      q->next=p->next;

      p=p->next;

      free(temp);

      }

      printf("%5d\n",p->data);

      }

      int main()

      {

      intn=7,m=3;

      LinkList*head1;

      head1=create(n);

      deletefun(head1,m);

      return0;

      }

      7..輸入一串字符,只包含“0-10”和“,”找出其中最小的數(shù)字和最大的數(shù)字(可能不止一個(gè)),輸出最后剩余數(shù)字個(gè)數(shù)。如輸入 “3,3,4,5,6,7,7”

      #include

      #include

      #include

      void main()

      {

      charstr[100];

      printf("輸入一組字符串:\n");

      scanf("%s",&str);

      intlen=strlen(str);

      intarray[100];

      intcount=0;

      for(inti=0;i

      {

      if(str[i]>='0'&&str[i]<='9')

      array[count++]=str[i]-'0';

      }

      array[count]='\0';

      intresult=count;

      intmin=array[0];

      intmax=array[0];

      for(intj=0;j

      {

      if(max

      max=array[j];

      elseif(min>array[j])

      min=array[j];

      }

      for(intk=0;k

      {

      if(array[k]==min)

      result--;

      if(array[k]==max)

      result--;

      }

      printf("%d\n",result);

      }

      8.輸入一組身高在170到190之間(5個(gè)身高),比較身高差,選出身高差最小的兩個(gè)身高;若身高差相同,選平均身高高的那兩個(gè)身高;從小到大輸出;

      如 輸入 170 181173 186 190 輸出 170 173

      #include

      #include

      #define N 5

      int main()

      {

      intHeight[N];

      intdmin;

      intH1,H2;

      inti,j,temp;

      printf("請輸入一組身高在170到190之間的數(shù)據(jù)(共5個(gè)):\n");

      for(intk=0;k

      scanf("%d",&Height[k]);

      printf("\n");

      for(i=0;i

      for(j=1;jHeight[j];j++)

      {

      temp=Height[j-1];

      Height[j-1]=Height[j];

      Height[j]=temp;

      }

      H1=Height[0];

      H2=Height[1];

      dmin=H2-H1;

      for(intm=2;m

      {

      if(Height[m]-Height[m-1]<=dmin)

      {

      H1=Height[m-1];

      H2=Height[m];

      dmin=Height[m]-Height[m-1];

      }

      }

      printf("身高差最小的兩個(gè)身高為:\n");

      printf("%d,%d\n",H1,H2);

      return0;

      }

      9. 刪除子串,只要是原串中有相同的子串就刪掉,不管有多少個(gè),返回子串個(gè)數(shù)。

      #include

      #include

      #include

      #include

      int delete_sub_str(const char *str,constchar *sub_str,char *result)

      {

      assert(str!= NULL && sub_str != NULL);

      constchar *p,*q;

      char*t,*temp;

      p= str;

      q= sub_str;

      t= result;

      intn,count = 0;

      n= strlen(q);

      temp= (char *)malloc(n+1);

      memset(temp,0x00,n+1);

      while(*p)

      {

      memcpy(temp,p,n);

      if(strcmp(temp,q)== 0 )

      {

      count++;

      memset(temp,0x00,n+1);

      p= p + n;

      }

      else

      {

      *t= *p;

      p++;

      t++;

      memset(temp,0x00,n+1);

      }

      }

      free(temp);

      returncount;

      }

      void main()

      {

      chars[100] = {‘\0’};

      intnum = delete_sub_str(“123abc12de234fg1hi34j123k”,”123”,s);

      printf(“Thenumber of sub_str is %d\r\n”,num);

      printf(“Theresult string is %s\r\n”,s);

      }

      10. 要求編程實(shí)現(xiàn)上述高精度的十進(jìn)制加法。要求實(shí)現(xiàn)函數(shù):

      void add (const char *num1,const char *num2, char *result)

      【輸入】num1:字符串形式操作數(shù)1,如果操作數(shù)為負(fù),則num1[0]為符號位'-'

      num2:字符串形式操作數(shù)2,如果操作數(shù)為負(fù),則num2[0]為符號位'-'

      【輸出】result:保存加法計(jì)算結(jié)果字符串,如果結(jié)果為負(fù),則result[0]為符號位。

      #include

      #include

      #include

      void move(char *str, int length) //移除字母前的"-"符號

      {

      if(str[0] != '-')

      return;

      int i;

      for(i = 0; i < length-1; i++)

      str[i] = str[i+1];

      str[i] = '\0';

      }

      intremove_zero(char *result, int length)

      {

      int count = 0;

      for(int i = length-1; i > 0; i--) //從最后開始移除0,直到遇到非0數(shù)字,只對最初位置上的0不予判斷

      {

      if(result[i] == '0')

      {

      result[i] = '\0';

      count++;

      }else

      return length-count;

      }

      return length - count;

      }

      voidreverse(char *result, int length) //將字符串倒轉(zhuǎn)

      {

      char temp;

      for(int i = 0; i <= (length-1)/2; i++)

      {

      temp = result[i];

      result[i] = result[length-1-i];

      result[length-1-i] = temp;

      }

      }

      intreal_add(char *str1, char *str2, char *result, const bool flag)

      {

      int len1 = strlen(str1);

      int len2 = strlen(str2);

      int n1, n2, another = 0; //another表示進(jìn)位

      int cur_rs = 0; //表示result的當(dāng)前位數(shù)

      int i, j;

      int curSum;

      for(i = len1-1, j = len2-1; i >= 0 && j >= 0; i--, j--)

      {

      n1 = str1[i] - '0';

      n2 = str2[j] - '0';

      curSum = n1 + n2 + another;

      result[cur_rs++] = curSum % 10 + '0';

      another = curSum / 10;

      }

      if(j < 0)

      {

      while(i >= 0) //遍歷str1剩余各位

      {

      n1 = str1[i--] - '0';

      curSum = n1 + another;

      result[cur_rs++] = curSum % 10 + '0';

      another = curSum / 10;

      }

      if(another != 0) //如果還有進(jìn)位未加上

      result[cur_rs++] = another + '0';

      }

      else

      {

      while(j >= 0)

      {

      n2 = str2[j--] - '0';

      curSum = n2 + another;

      result[cur_rs++] = curSum % 10 + '0';

      another = curSum / 10;

      }

      if(another != 0)

      result[cur_rs++] = another + '0';

      }

      result[cur_rs] = '\0';

      cur_rs = remove_zero(result, cur_rs);

      if(!flag)

      {

      result[cur_rs++] = '-';

      result[cur_rs] = '\0';

      }

      reverse(result, strlen(result));

      return cur_rs;

      }

      intreal_minus(char *str1, char *str2, char *result) //使用str1減去str2

      {

      char big[100], small[100];

      int big_len, sml_len;

      int len1 = strlen(str1);

      int len2 = strlen(str2);

      bool flag = false; //用于標(biāo)記str2是否比str1大

      if(len1 < len2)

      flag = true;

      else if(len1 == len2)

      {

      if(strcmp(str1, str2) == 0)

      {

      result[0] = '0';

      result[1] = '\0';

      return 1;

      }else if(strcmp(str1,str2) < 0)

      flag = true;

      }

      if(flag) //將str1和str2交換,確保str1指向的值是其中較大者,最后通過flag確定要不要給前面加-號

      {

      char *temp = str1;

      str1 = str2;

      str2 = temp;

      len1 = strlen(str1);

      len2 = strlen(str2);

      }

      int n1, n2, another = 0; //another表示是否有借位

      int i, j;

      int cur_rs = 0;

      int curMinus;

      for(i = len1-1, j =len2-1; i>=0 && j>=0; i--,j--)

      {

      n1 = str1[i] - '0';

      n2 = str2[j] - '0';

      if(n1 >= n2+another)

      {

      result[cur_rs++] = (n1-n2-another)+'0';

      another = 0;

      }

      else

      {

      result[cur_rs++] = (n1+10-n2-another)+ '0';

      another = 1;

      }

      }

      while(i >= 0)

      {

      n1 = str1[i--] - '0';

      if(another != 0)

      {

      n1 -= another;

      another = 0;

      }

      result[cur_rs++] = n1 + '0';

      }

      result[cur_rs] = '\0';

      cur_rs = remove_zero(result, cur_rs);

      if(flag)

      {

      result[cur_rs++] = '-';

      result[cur_rs] = '\0';

      }

      reverse(result, cur_rs);

      return cur_rs;

      }

      voidaddi(const char *num1, const char *num2, char *result)

      {

      int len1 = strlen(num1);

      int len2 = strlen(num2);

      int rs_len;

      if(!len1 || !len2)

      return;

      char str1[100], str2[100];

      strncpy(str1, num1, len1);

      str1[len1] = '\0';

      strncpy(str2, num2, len2);

      str2[len2] = '\0';

      if(str1[0] == '-' && str2[0] == '-')

      {

      move(str1, len1);

      move(str2, len2);

      rs_len = real_add(str1, str2, result, false);

      }else if(str1[0] == '-')

      {

      move(str1, len1);

      rs_len = real_minus(str2, str1, result);

      }

      else if(str2[0] == '-')

      {

      move(str2, len2);

      rs_len = real_minus(str1, str2, result);

      }else

      rs_len = real_add(str1, str2, result, true);

      }

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

      intmain()

      {

      char num1[100],num2[100];

      printf("請輸入兩個(gè)整型數(shù)據(jù):\n");

      scanf("%s%s",num1,num2);

      char result[100];

      memset(result, 0, 100);

      addi(num1,num2, result);

      printf("%s\n", result);

      return 0;

      }

    【華為認(rèn)證上機(jī)考試題】相關(guān)文章:

    華為Java上機(jī)考試題07-04

    2016年華為上機(jī)考試題10-27

    2016年華為認(rèn)證考試題及答案07-25

    華為上機(jī)試題匯總01-23

    華為認(rèn)證中的HCIE認(rèn)證08-09

    2016年華為認(rèn)證考試題庫02-26

    華為認(rèn)證詳解08-27

    2016年華為HCDA認(rèn)證考試題庫07-16

    2016年華為hcie認(rèn)證考試題庫06-29

    華為專業(yè)認(rèn)證分類07-11

    91久久大香伊蕉在人线_国产综合色产在线观看_欧美亚洲人成网站在线观看_亚洲第一无码精品立川理惠

      亚洲高清一区二区三区不卡 | 视频一区二区中文字幕 | 亚洲国产精品综合久久2007 | 中文字幕亚洲综合小综合在线 | 亚洲欧美中文字幕日韩二区 | 日韩精品一区二区三区中文不卡 |