<dfn id="w48us"></dfn><ul id="w48us"></ul>
  • <ul id="w48us"></ul>
  • <del id="w48us"></del>
    <ul id="w48us"></ul>
  • 華為認證考試題庫

    時間:2024-10-24 02:39:33 華為認證 我要投稿

    2016年華為認證考試題庫

      華為認證覆蓋路由交換、無線局域網、無線、傳送網、安全、統一通信、視訊、云計算、服務器、存儲以及ICT融合設計等11個技術領域。下面快跟yjbys小編一起來看看關于華為認證的考試題庫,希望能幫助到各位考生!

    2016年華為認證考試題庫

      1.第一題的題目大概是輸入整型數組求數組的最小數和最大數之和,例如輸入1,2,3,4則輸出為5,當輸入只有一個數的時候,則最小數和最大數都是該數,例如只輸入1,則輸出為2;另外數組的長度不超過50

      #include

      main()

      {

      intnum[50]={0};

      inti,n;

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

      scanf("%d",&n);

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

      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("數組中最大與最小值之和:%d\n",sum);

      return0;

      }

      2.求兩個長長整型的數據的和并輸出,例如輸入1233333333333333。。。 3111111111111111111111111.。。。,則輸出。。。。

      #include

      #include

      #include

      main()

      {

      char*num1,*num2; //兩個長長整型數據

      char*sum;

      // inttemp;

      int len_num1,len_num2; // 兩個長長整型數據的長度

      intlen_max,len_min;

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

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

      printf("輸入兩個長長整型數據:");

      scanf("%s",num1);

      printf("輸入兩個長長整型數據:");

      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--) //實現進位操作

      {

      // 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("輸出兩長長整型數據之和:%s\n",outsum);

      return0;

      }

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

      比如字符串“abacacde”過濾結果為“abcde”。

      要求實現函數:

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

      【輸入】 pInputStr:輸入字符串

      lInputLen: 輸入字符串長度

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

      #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)組成的字符串。請編寫一個字符串壓縮程序,將字符串中連續出席的重復字母進行壓縮,并輸出壓縮后的字符串。

      壓縮規則:

      1. 僅壓縮連續重復出現的字符。比如字符串"abcbc"由于無連續重復字符,壓縮后的字符串還是"abcbc".

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

      要求實現函數:

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

      【輸入】 pInputStr: 輸入字符串

      lInputLen: 輸入字符串長度

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

      #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以內正整數的加、減運算式,請編寫一個程序輸出運算結果字符串。

      輸入字符串的格式為:“操作數1 運算符 操作數2”,“操作數”與“運算符”之間以一個空格隔開。

      補充說明:

      1. 操作數為正整數,不需要考慮計算結果溢出的情況。

      2. 若輸入算式格式錯誤,輸出結果為“0”。

      要求實現函數:

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

      【輸入】 pInputStr: 輸入字符串

      lInputLen: 輸入字符串長度

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

      #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個),圍成一圈,從某人開始數到第三個的人出列,再接著從下一個人開始數,最終輸出最終出列的人

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

      #include

      #include

      #include

      #include

      typedef struct Node

      {

      intdata;

      structNode *next;

    更多相關文章推薦閱讀:

    1.2016年華為認證考試題庫

    2.2016年華為hcie認證考試題庫

    3.2016年華為認證認證試題(筆試)

    4.2016年華為認證考試題及答案

    5.2016年華為上機考試題

    6.2016年華為HCDA認證考試題庫

    7.2016年華為筆試題及及答案

    8.2016年華為筆試面試題及答案

    9.2016年華為HCDA認證考試筆試題及答案

      }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; //使鏈表尾連接鏈表頭,形成循環鏈表

      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”和“,”找出其中最小的數字和最大的數字(可能不止一個),輸出最后剩余數字個數。如輸入 “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個身高),比較身高差,選出身高差最小的兩個身高;若身高差相同,選平均身高高的那兩個身高;從小到大輸出;

      如 輸入 170 181173 186 190 輸出 170 173

      #include

      #include

      #define N 5

      int main()

      {

      intHeight[N];

      intdmin;

      intH1,H2;

      inti,j,temp;

      printf("請輸入一組身高在170到190之間的數據(共5個):\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("身高差最小的兩個身高為:\n");

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

      return0;

      }

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

      #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. 要求編程實現上述高精度的十進制加法。要求實現函數:

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

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

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

      【輸出】result:保存加法計算結果字符串,如果結果為負,則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數字,只對最初位置上的0不予判斷

      {

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

      {

      result[i] = '\0';

      count++;

      }else

      return length-count;

      }

      return length - count;

      }

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

      {

      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表示進位

      int cur_rs = 0; //表示result的當前位數

      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) //如果還有進位未加上

      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; //用于標記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';

    更多相關文章推薦閱讀:

    1.2016年華為認證考試題庫

    2.2016年華為hcie認證考試題庫

    3.2016年華為認證認證試題(筆試)

    4.2016年華為認證考試題及答案

    5.2016年華為上機考試題

    6.2016年華為HCDA認證考試題庫

    7.2016年華為筆試題及及答案

    8.2016年華為筆試面試題及答案

    9.2016年華為HCDA認證考試筆試題及答案

      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("請輸入兩個整型數據:\n");

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

      char result[100];

      memset(result, 0, 100);

      addi(num1,num2, result);

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

      return 0;

      }

      11. 描述:10個學生考完期末考試評卷完成后,A老師需要劃出及格線,要求如下:

      (1) 及格線是10的倍數;

      (2) 保證至少有60%的學生及格;

      (3) 如果所有的學生都高于60分,則及格線為60分

      輸入:輸入10個整數,取值0~100

      輸出:輸出及格線,10的倍數

      #include

      void bubblesort(int arr[])

      {

      inti,j,temp;

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

      for(j=0;j<9-i&&arr[j]>arr[j+1];j++)

      {

      temp=arr[j];

      arr[j]=arr[j+1];

      arr[j+1]=temp;

      }

      }

      int GetPassLine(int a[])

      {

      bubblesort(a);

      if(a[0]>=60)

      return60;

      else

      return(((int)a[4]/10)*10);

      }

      main()

      {

      inta[10]={0};

      intresult;

      printf("請隨機輸入10個成績(0-100):\n");

      scanf("%d%d%d%d%d%d%d%d%d%d",&a[0],&a[1],&a[2],&a[3],&a[4],&a[5],&a[6],&a[7],&a[8],&a[9]);

      printf("\n");

      result=GetPassLine(a);

      printf("及格線為:%d\n",result);

      return1;

      }

      12. 描述:一條長廊里依次裝有n(1 ≤ n ≤ 65535)盞電燈,從頭到尾編號1、2、3、…n-1、n。每盞電燈由一個拉線開關控制。開始,電燈全部關著。

      有n個學生從長廊穿過。第一個學生把號碼凡是1的倍數的電燈的開關拉一下;接著第二個學生把號碼凡是2的倍數的電燈的開關拉一下;接著第三個學生把號碼凡是3的倍數的電燈的開關拉一下;如此繼續下去,最后第n個學生把號碼凡是n的倍數的電燈的開關拉一下。n個學生按此規定走完后,長廊里電燈有幾盞亮著。注:電燈數和學生數一致。

      輸入:電燈的數量

      輸出:亮著的電燈數量

      樣例輸入:3

      樣例輸出:1

      #include

      #define Max_Bubl_Num 65535

      int GetLightLampNum(int n)

      {

      intBublNum[Max_Bubl_Num]={0}; //0表示燈滅,1表示燈亮

      unsignedint i,j;

      unsignedint count=0;

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

      for(j=i;j<=n&&j%i==0;j++)

      {

      BublNum[j-1]+=1;

      BublNum[j-1]=BublNum[j-1]%2;

      }

      for(intk=0;k

      {

      if(BublNum[k]==1)

      count++;

      }

      returncount;

      }

      int main()

      {

      intn,result;

      printf("請輸入燈的數量(1-65535):\n");

      scanf("%d",&n);

      result=GetLightLampNum(n);

      printf("最后亮燈的數量為:%d\n",result);

      return0;

      }

      13. 描述:已知2條地鐵線路,其中A為環線,B為東西向線路,線路都是雙向的。經過的站點名分別如下,兩條線交叉的換乘點用T1、T2表示。編寫程序,任意輸入兩個站點名稱,輸出乘坐地鐵最少需要經過的車站數量(含輸入的起點和終點,換乘站點只計算一次)。

      地鐵線A(環線)經過車站:A1 A2 A3 A4 A5 A6A7 A8 A9 T1 A10 A11 A12 A13 T2 A14 A15 A16 A17 A18

      地鐵線B(直線)經過車站:B1 B2 B3 B4 B5 T1B6 B7 B8 B9 B10 T2 B11 B12 B13 B14 B15

      輸入:輸入兩個不同的站名

      輸出:輸出最少經過的站數,含輸入的起點和終點,換乘站點只計算一次

      輸入樣例:A1 A3

      輸出樣例:3

      #include

      #include

      #include

      #include

      using namespace std;

      #define MAX 35

      #define SUBWAY_A 20

      #define SUBWAY_B 15

      typedef struct node{

      int adjvex;

      struct node *next;

      }edgenode;

      typedef struct{

      char name[10];

      bool flag;

      edgenode *link;

      }vexnode;

      const charsubway_name1[SUBWAY_A][10]={"A1","A2","A3","A4","A5","A6","A7","A8","A9","T1","A10","A11","A12","A13","T2","A14","A15","A16","A17","A18"};

      const charsubway_name2[SUBWAY_B][10]={"B1","B2","B3","B4","B5","B6","B7","B8","B9","B10","B11","B12","B13","B14","B15"};

      void creat(vexnode ga[]){

      int i;

      edgenode *p;

      for(i=0;i

      ga[i].link=NULL;

      ga[i].flag=true;

      if(i

      elsestrcpy(ga[i].name,subway_name2[i-20]);

      }

      //A地鐵建鄰接表

      for(i=1;i

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

      p->adjvex=i-1;

      p->next=NULL;

      ga[i].link=p;

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

      p->adjvex=i+1;

      p->next=NULL;

      ga[i].link->next=p;

      if(i==9){

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

      p->adjvex=SUBWAY_A+4;

      p->next=NULL;

      ga[i].link->next->next=p;

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

      p->adjvex=SUBWAY_A+5;

      p->next=NULL;

      ga[i].link->next->next->next=p;

      }

      else if(i==14){

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

      p->adjvex=SUBWAY_A+9;

      p->next=NULL;

      ga[i].link->next->next=p;

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

      p->adjvex=SUBWAY_A+10;

      p->next=NULL;

      ga[i].link->next->next->next=p;

      }

      }

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

      p->adjvex=SUBWAY_A-1;

      p->next=NULL;

      ga[0].link=p;

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

      p->adjvex=1;

      p->next=NULL;

      ga[0].link->next=p;

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

      p->adjvex=SUBWAY_A-2;

      p->next=NULL;

      ga[SUBWAY_A-1].link=p;

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

      p->adjvex=0;

      p->next=NULL;

      ga[SUBWAY_A-1].link->next=p;

      //B地鐵建鄰接表

      for(i=1;i

      if(i==4||i==5||i==9||i==10)continue;

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

      p->adjvex=SUBWAY_A+i-1;

      p->next=NULL;

      ga[i+SUBWAY_A].link=p;

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

      p->adjvex=SUBWAY_A+i+1;

      p->next=NULL;

      ga[i+SUBWAY_A].link->next=p;

      }

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

      p->adjvex=SUBWAY_A+3;

      p->next=NULL;

      ga[SUBWAY_A+4].link=p;

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

      p->adjvex=9;

      p->next=NULL;

      ga[SUBWAY_A+4].link->next=p;

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

      p->adjvex=9;

      p->next=NULL;

    更多相關文章推薦閱讀:

    1.2016年華為認證考試題庫

    2.2016年華為hcie認證考試題庫

    3.2016年華為認證認證試題(筆試)

    4.2016年華為認證考試題及答案

    5.2016年華為上機考試題

    6.2016年華為HCDA認證考試題庫

    7.2016年華為筆試題及及答案

    8.2016年華為筆試面試題及答案

    9.2016年華為HCDA認證考試筆試題及答案

      ga[SUBWAY_A+5].link=p;

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

      p->adjvex=SUBWAY_A+6;

      p->next=NULL;

      ga[SUBWAY_A+5].link->next=p;

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

      p->adjvex=SUBWAY_A+8;

      p->next=NULL;

      ga[SUBWAY_A+9].link=p;

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

      p->adjvex=14;

      p->next=NULL;

      ga[SUBWAY_A+9].link->next=p;

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

      p->adjvex=14;

      p->next=NULL;

      ga[SUBWAY_A+10].link=p;

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

      p->adjvex=SUBWAY_A+11;

      p->next=NULL;

      ga[SUBWAY_A+10].link->next=p;

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

      p->adjvex=SUBWAY_A+1;

      p->next=NULL;

      ga[SUBWAY_A].link=p;

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

      p->adjvex=SUBWAY_A+SUBWAY_B-2;

      p->next=NULL;

      ga[SUBWAY_A+SUBWAY_B-1].link=p;

      // 打印各鄰接節點

      for(i=0;i

      printf("%s:",ga[i].name);

      edgenode *s;

      s=ga[i].link;

      while(s!=NULL){

      printf("->%s",ga[s->adjvex].name);

      s=s->next;

      }

      printf("\n");

      }

      }

      int main(){

      vexnode ga[MAX];

      creat(ga);

      int i;

      char str[2][10];

      while(scanf("%s%s",str[0],str[1])!=EOF){

      int temp=0;

      for(i=0;i

      ga[i].flag=true;

      if(!strcmp(str[0],ga[i].name))temp=i;

      }

      queueq;

      q.push(ga[temp]);

      ga[temp].flag=false;

      int count=0;

      int start=0;

      int end=1;

      bool find_flag=false;

      while(!q.empty()){

      if(find_flag) break;

      count++;

      printf("************************\n");

      printf("第%d層搜索:",count);

      int temp_end=end;

      while(start

      printf("%s",q.front().name);

      if(!strcmp(q.front().name,str[1])){

      find_flag=true;

      break;

      }

      edgenode *s;

      s=q.front().link;

      while(s!=NULL){

      if(ga[s->adjvex].flag){

      q.push(ga[s->adjvex]);

      ga[s->adjvex].flag=false;

      end++;

      //printf("%s ",ga[s->adjvex].name);

      }

      s=s->next;

      }

      q.pop();

      start++;

      }

      printf("\n");

      }

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

      }

      return 0;

      }

      14. 字串轉換

      問題描述:

      將輸入的字符串(字符串僅包含小寫字母‘a’到‘z’),按照如下規則,循環轉換后輸出:a->b,b->c,…,y->z,z->a;若輸入的字符串連續出現兩個字母相同時,后一個字母需要連續轉換2次。例如:aa 轉換為 bc,zz 轉換為 ab;當連續相同字母超過兩個時,第三個出現的字母按第一次出現算。

      要求實現函數:

      void convert(char *input,char* output)

      【輸入】 char *input , 輸入的字符串

      【輸出】 char *output ,輸出的字符串

      【返回】 無

      #include

      #include

      #include

      void convert(char *input,char* output)

      {

      if(input==NULL)

      return;

      chartemp='\0';

      intlen_input=strlen(input);

      inti;

      intflag=0;

      for(i=0;i

      {

      if(input[i]!=temp)

      {

      output[i]=(input[i]-'a'+1)%26+'a';

      temp=input[i];

      flag=1;

      }

      else

      {

      if(flag==1)

      {

      output[i]=(input[i]-'a'+2)%26+'a';

      temp=input[i];

      flag=0;

      }

      else

      {

      output[i]=(input[i]-'a'+1)%26+'a';

      temp=input[i];

      flag=1;

      }

      }

      }

      output[i]='\0';

      }

      void main()

      {

      char*input="xyz";

      charoutput[256];

      // scanf("%s",input);

      convert(input,output);

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

      }

      15. 在給定字符串中找出單詞( “單詞”由大寫字母和小寫字母字符構成,其他非字母字符視為單詞的間隔,如空格、問號、數字等等;另外單個字母不算單詞);找到單詞后,按照長度進行降序排序,(排序時如果長度相同,則按出現的順序進行排列),然后輸出到一個新的字符串中;如果某個單詞重復出現多次,則只輸出一次;如果整個輸入的字符串中沒有找到單詞,請輸出空串。輸出的單詞之間使用一個“空格”隔開,最后一個單詞后不加空格。

      要求實現函數:

      void my_word(charinput[], char output[])

      【輸入】 char input[], 輸入的字符串

      【輸出】 char output[],輸出的字符串

      【返回】 無

      #include

      #include

      #include

      void my_word(char input[],charoutput[])

      {

      char *p;

      char *temp;

      char *word[10];

      int len_input=strlen(input);

      int i,j;

      char except[] = ",";

      char *blank = " ";

      i=0;

      for (i=0;i

      {

      if (input[i]<'A' || (input[i]>'Z'&&input[i]<'a') ||input[i]>'z')

      {

      input[i]=',';

      }

      }

      j=0;

      /*保存取出的單詞*/

      p= strtok(input,except);

      while(NULL!=p)

      {

      word[j++]=p;

      p= strtok(NULL,except);

      }

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

      printf("%s",word[i]);

      /*對單詞按照長度降序排序,冒泡法*/

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

      {

      for (j=1;j<5-i;j++)

      {

      if(strlen(word[j-1])

      {

      temp=word[j];

      word[j]=word[j-1];

      word[j-1]=temp;

      }

      }

      }

      /*刪除相同單詞*/

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

      {

      for(j=i+1;j<5;j++)

      {

      if(strcmp(word[i],word[j])==0)

      word[j]="\0";

      }

      }

      /*將單詞連接起來輸出*/

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

      {

      if (0==j)

      {

      strncpy(output,word[j],strlen(word[j])+1);

      }

      else

      {

      strcat(output,blank);

      strcat(output,word[j]);

      }

      }

      return ;

      }

      int main()

      {

      char input[] ="some local buses, some1234123drivers";

      printf("篩選之前的字符串:%s\n",input);

      char output[30];

      my_word(input,output);

      printf("篩選之后的字符串:%s",output);

      printf("\n");

      return 0;

      }

      16. 數組中數字都兩兩相同,只有一個不同,找出該數字:

      int findUnique(int* a, int len)

      {

      int i = 1;

      int temp =a[0];

      for(; i

      {

      temp= temp ^ a[i];

      }

      printf("%d", temp);

      }

      17.題目二:數組中數字兩兩相同,有兩個不同,找出這兩個:

      #include

      int a[] = {1,1,2,4,3,3,2,5};

      int findXorSum(int* a, int len)

      {

      int i = 0;

      int temp =0;

      for(; i

      {

      temp= temp ^ a[i];

      }

      return temp;

      }

      int findFirstBit1(int n)

      {

      int count =1;

      while(!( n &1))

      {

      n =n>>1;

      count++;

      }

      returncount;

      }

      int isBit1(int a, int count)

      {

      a= a >> count-1;

      return(a & 1);

      }

      void findTwoUnique(int* a, int len)

      {

      int i = 0;

      int m = 0, n= 0;

      int temp =findXorSum(a, len);

      int count =findFirstBit1(temp);

      for(; i

      {

      if(isBit1(a[i],count))

      {

      m= m ^ a[i];

      }

      else

      {

      n= n ^ a[i];

      }

      }

      printf("%d,%d", m, n);

      }

      int main()

      {

      findTwoUnique(a,8);

      }

      18. 鏈表翻轉。給出一個鏈表和一個數k,比如鏈表1→2→3→4→5→6,k=2,則翻轉后2→1→4→3→6→5,若k=3,翻轉后3→2→1→6→5→4,若k=4,翻轉后4→3→2→1→5→6,用程序實現

      思想:采用遍歷鏈表,分成length/k組,對每組進行逆轉,逆轉的同時要將逆轉后的尾和頭連接起來

    更多相關文章推薦閱讀:

    1.2016年華為認證考試題庫

    2.2016年華為hcie認證考試題庫

    3.2016年華為認證認證試題(筆試)

    4.2016年華為認證考試題及答案

    5.2016年華為上機考試題

    6.2016年華為HCDA認證考試題庫

    7.2016年華為筆試題及及答案

    8.2016年華為筆試面試題及答案

    9.2016年華為HCDA認證考試筆試題及答案

      //#include "stdafx.h"

      #include "stdio.h"

      #include "stdlib.h"

      #include

      typedef struct Node{

      intvalue;

      Node*next;

      }LinkList;

      void Converse(LinkList* pPre,LinkList*pCur)

      { //鏈表逆轉

      LinkList*p = NULL;

      LinkList*pNext = NULL;

      p= pPre->next;

      LinkList*p1 = NULL;

      if(pCur!=NULL)

      pNext= pCur->next;

      while(p!=pNext)

      {

      p1= p->next;

      p->next= pPre;

      pPre= p;

      p= p1;

      }

      }

      int main()

      {

      intcount = 0, k,i=0,j=0,flag = 1,length=0,groups = 0;

      scanf("%d",&k);

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

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

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

      LinkList*head = NULL;

      LinkList* pTempTail = NULL; //指向逆轉之后的尾部

      LinkList*pTempHead = NULL;

      pCur->value= 1;

      pPre= pCur; //創建初始鏈表

      for(i=2;i<=6;i++){

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

      node->value= i;

      pCur->next= node;

      pCur= node;

      }

      pCur->next= NULL;//最后一定要置NULL,c++中用new則無須置NULL

      pCur= pPre;

      while(pCur!=NULL)

      {

      length++;

      pCur= pCur->next;

      }

      i=0;

      groups= length/k; //分成K段

      pCur= pPre;

      while(i<=groups)

      {

      count= 0;

      while(count

      {

      pCur= pCur->next;

      count++;

      }

      if(i

      {

      pNext= pCur->next;

      pTempHead= pCur; /*沒做翻轉之前的頭部,變成了翻轉之后的尾部*/

      if(flag== 0)

      {

      pTempTail->next= pTempHead;

      }

      pTempTail= pPre;

      Converse(pPre,pCur);

      //pTempTail= pPre;

      if(flag==1)

      {

      head= pCur;

      flag= 0;

      }

      pCur= pNext;

      }

      else

      {

      pTempTail->next= pNext;

      }

      pPre= pCur;

      i++;

      }

      pCur= head;

      while(j

      j++;

      printf("%d",pCur->value);

      pCur= pCur->next;

      }

      printf("\n");

      // system("pause");

      return0;

      }

      19. 鏈表相鄰元素翻轉,如a->b->c->d->e->f-g,翻轉后變為:b->a->d->c->f->e->g

      #include

      #include

      #include

      typedef struct node{

      charval;

      structnode* pNext;

      }Node;

      Node* CreateList(int n);

      void Traverslist(Node* pHead);

      Node* TransNeighbor(Node* pHead);

      int main(){

      Node*pHead = CreateList(7);

      printf("beforetransform\n");

      Traverslist(pHead);

      TransNeighbor(pHead);

      printf("\naftertransform\n");

      Traverslist(pHead);

      getchar();

      return1;

      }

      //創建新鏈表

      Node* CreateList(int n){

      Node*pHead = (Node*)malloc(sizeof(Node));

      Node*pTail = pHead;

      pTail->pNext=NULL;

      inti;

      for(i=0;i < n; i++){

      Node* pNew = (Node*)malloc(sizeof(Node));

      pNew->val = 'a'+i;

      pTail->pNext = pNew;

      pNew->pNext = NULL;

      pTail = pNew;

      }

      returnpHead;

      }

      void Traverslist(Node* pHead){

      Node*p = pHead->pNext;

      intisFirst = 0;

      while(p!=NULL)

      {

      if(isFirst==0)

      {

      printf("%c",p->val);

      isFirst=1;

      }else{

      printf("->%c",p->val);

      }

      p= p->pNext;

      }

      return;

      }

      Node* TransNeighbor(Node* pHead){

      Node*p = pHead->pNext;

      while(p->pNext!=NULL &&p->pNext->pNext!=NULL)

      {

      charvalue = p->val;

      p->val=p->pNext->val;

      p->pNext->val=value;

      p=p->pNext->pNext;

      }

      returnpHead;

      }

      20. 輸入一串字符串,其中有普通的字符與括號組成(包括‘(’、‘)’、‘[’,']'),要求驗證括號是否匹配,如果匹配則輸出0、否則輸出1.

      #include

      #include

      //#define MAX 100

      int main()

      {

      chara[100],c[]="(((1+2))";

      int i=0,j=0;;

      int flag=0;

      while(c[i]!=NULL&&flag==0)

      {

      switch(c[i])

      {

      case('('):

      case('['):

      a[j++]=c[i];break;

      case(')'):

      if(a[j-1]=='(')

      {

      a[j-1]='\0';

      j--;

      }

      else

      flag=1;

      break;

      case(']'):

      if(a[j-1]=='[')

      {

      a[j-1]='\0';

      j--;

      }

      else

      flag=1;

      break;

      }

      i++;

      }

      if(j!=0) flag=1;

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

      return 0;

      }

      方法2:#include

      #include

      #include // !!!分配內存頭文件

      #define m 20

      typedef char ElemType;

      typedef struct

      {

      ElemType stack[m];

      int top;

      }stacknode;

      stacknode *sp;

      Init(stacknode *st)

      {

      st->top=0;

      return 0;

      }

      void Push(stacknode *st,ElemType x)

      {

      if(st->top==m)

      printf("The stack isoverflow!\n");

      else

      {

      st->top=st->top+1;

      st->stack[st->top]=x;

      }

      }

      void Pop(stacknode *st)

      {

      st->top=st->top-1;

      }

      main()

      {

      char s[m]="(()";

      int i;

      printf("Creat astack!\n");

      sp = (stacknode*)malloc(sizeof(stacknode)); // !!!添加的語句

      Init(sp);

      printf("Input aexpression:\n");

      // gets(s);

      for(i=0;i

      {

      if(s[i]=='(')

      Push(sp,s[i]);

      if(s[i]==')')

      Pop(sp);

      }

      if(sp->top==0)

      printf("左右括號是匹配的!\n");

      else

      printf("左右括號是不匹配的!\n");

      return 0;

      }

      21.將第一行中含有第二行中“23”的數輸出并排序

      2.輸入一行數字:123 423 5645 875 186523

      在輸入第二行:23

      將第一行中含有第二行中“23”的數輸出并排序

      結果即:123 423 186523

      #include

      #define M 20

      int main()

      {

      int a[M];

      int i,j,s,temp;

      int sort[M],t=0;

      char c=' ';

      i=0;

      while(c!='\n')

      {

      scanf("%d%c",&temp,&c);

      a[i++]=temp;

      }

      scanf("%d",&s);

      for(j=0;j

      {

      temp=a[j];

      if(temp%100==s)

      {

      sort[t++]=a[j];

      }

      else

      temp/=10;

      }

      for(i=0;i

      for(j=0;j

      {

      if(sort[j]>sort[j+1])

      {

      temp=sort[j+1];

      sort[j+1]=sort[j];

      sort[j]=temp;

      }

      }

      for(i=0;i

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

      printf("\n");

      return 0;

      }

      22輸入m個字符串 和一個整數n, 把字符串M化成以N為單位的段,不足的位數用0補齊。

      如 n=8 m=9 ,

      123456789劃分為:12345678

      90000000

      123化為 :12300000

      #include

      #include

      int main()

      {

      char c[200]={'\0'};

      scanf("%s",&c);

      int n,i,j;

      int len=strlen(c);

      scanf("%d",&n);

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

      {

      j=i%n;

      printf("%c",c[i-1]);

      if(j==0)

      printf("\n");

      }

      if(j!=0)

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

    更多相關文章推薦閱讀:

    1.2016年華為認證考試題庫

    2.2016年華為hcie認證考試題庫

    3.2016年華為認證認證試題(筆試)

    4.2016年華為認證考試題及答案

    5.2016年華為上機考試題

    6.2016年華為HCDA認證考試題庫

    7.2016年華為筆試題及及答案

    8.2016年華為筆試面試題及答案

    9.2016年華為HCDA認證考試筆試題及答案

      printf("0");

      return 0;

      }

      23將 電話號碼 one two 。。。nine zero

      翻譯成1 2 。。9 0

      中間會有double

      例如輸入:OneTwoThree

      輸出:123

      輸入:OneTwoDoubleTwo

      輸出:1222

      輸入:1Two2 輸出:ERROR

      輸入:DoubleDoubleTwo 輸出:ERROR

      有空格,非法字符,兩個Double相連,Double位于最后一個單詞都錯誤

      #include

      #include

      #include

      int main()

      {

      chara[11][11]={"zero","one","two","three","four","five","six","seven","eight","nine","double"};

      char temp[11], c=' ';

      int i,j,f,d=0;

      while(c!='\n')

      {

      scanf("%s%c",&temp,&c);

      f=0;

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

      {

      if(!strcmp(temp,a[j])&&j<10)

      {

      printf("%d",j);

      f=1;

      if(d==1)

      {

      printf("%d",j);

      d=0;

      }

      }

      elseif(!strcmp(temp,a[j])&&j==10)

      {

      d=1;

      f=1;

      }

      }

      if(f==0)

      break;

      }

      if(d==1||f==0)

      printf("error\n");

      printf("\n");

      return 0;

      }

      24.將整數倒序輸出,剔除重復數據

      輸入一個整數,如12336544,或1750,然后從最后一位開始倒過來輸出,最后如果是0,則不輸出,輸出的數字是不帶重復數字的,所以上面的輸出是456321和571。如果是負數,比如輸入-175,輸出-571。

      #include

      #include

      #include

      #include

      int main()

      {

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

      scanf("%s",input);

      inta[10]={0},i,flag=0,flag1=0;

      int len=strlen(input);

      if(input[0]=='-')

      {

      flag=1;

      for(i=0;i

      input[i]=input[i+1];

      }

      intlen1=strlen(input);

      int n[50],temp;

      int count=0;

      for(i=0;i

      {

      temp=input[i]-'0';

      if(a[temp]==0)

      {

      n[count++]=temp;

      a[temp]=1;

      }

      }

      n[count]='\0';

      if(flag==1)

      printf("-");

      for(intii=count-1;ii>=0;ii--)

      {

      if(n[ii]!=0||flag1!=0)

      {

      printf("%d",n[ii]);

      flag1=1;

      }

      }

      printf("\n");

      return 0;

      }

      25.編程的時候,if條件里面的“(”、“)”括號經常出現不匹配的情況導致編譯不過,請編寫程序檢測輸入一行if語句中的圓括號是否匹配正確。同時輸出語句中出現的左括號和右括號數量,如if((a==1)&&(b==1))是正確的,而if((a==1))&&(b==1))是錯誤的。注意if語句的最外面至少有一對括號。提示:用堆棧來做。

      輸入:if((a==1)&&(b==1))

      輸出:RIGTH 3 3

      輸入:if((a==1))&&(b==1))

      輸出:WRONG 3 4

      #include

      #include

      int main()

      {

      char s[800]={'\0'};

      scanf("%s",&s);

      // char s[]="if(())";

      int len=strlen(s);

      int i,left=0,right=0;

      int a[50],k=0,flag=1;

      for(i=0;i

      {

      if(s[i]=='(')

      {

      left++;

      a[k]=1;

      k++;

      }

      elseif(s[i]==')')

      {

      right++;

      if(a[k-1]==1&&k>0)

      {

      a[k-1]=0;

      k--;

      }

      else

      flag=0;

      }

      if((i==2&&s[i]!='(')||(i==len-1&&s[i]!=')'))

      flag=0;

      }

      if(a[0]==0&&flag!=0)

      printf("RIGHT");

      else

      printf("WRONG");

      printf("%d%d\n",left,right);

      return 0;

      }

      約瑟夫問題

      輸入一個由隨機數組成的數列(數列中每個數均是大于0的整數,長度已知),和初始計數值m。從數列首位置開始計數,計數到m后,將數列該位置數值替換計數值m,并將數列該位置數值出列,然后從下一位置從新開始計數,直到數列所有數值出列為止。如果計數到達數列尾段,則返回數列首位置繼續計數。請編程實現上述計數過程,同時輸出數值出列的順序

      比如:輸入的隨機數列為:3,1,2,4,初始計數值m=7,從數列首位置開始計數(數值3所在位置)

      第一輪計數出列數字為2,計數值更新m=2,出列后數列為3,1,4,從數值4所在位置從新開始計數

      第二輪計數出列數字為3,計數值更新m=3,出列后數列為1,4,從數值1所在位置開始計數

      第三輪計數出列數字為1,計數值更新m=1,出列后數列為4,從數值4所在位置開始計數

      最后一輪計數出列數字為4,計數過程完成。

      輸出數值出列順序為:2,3,1,4。

      要求實現函數:

      void array_iterate(int len, int input_array[], int m, int output_array[])

      【輸入】 int len:輸入數列的長度;

      int intput_array[]:輸入的初始數列

      int m:初始計數值

      【輸出】 int output_array[]:輸出的數值出列順序

      【返回】 無

      示例:

      輸入:int input_array[] = {3,1,2,4},int len = 4, m=7

      輸出:output_array[] = {2,3,1,4}

      解題思路:

      每次出列一個數值,需要對m、input_array、output_array、輸出位置outPos、起始位置startPos進行更新;

      對于輸出位置outPos的計算是關鍵!通過分析可知,outPos=(startPos+m-1)%num

      代碼實現:

      view plaincopy to clipboardprint?

      #include

      voidprint_array(int len, int array[])

      {

      for(int i=0; i

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

      printf("\n");

      }

      //input_array:a[0]...a[len-1]

      voidarray_iterate(int len, int input_array[], int m, int output_array[])

      {

      int startPos=0;

      int outPos;

      int nIter=len-1;

      int num=len;

      for(; nIter>=0; nIter--)

      {

      outPos=(m+startPos-1)%num;

      m=input_array[outPos];

      startPos=outPos;

      printf("outPos is %d, new m is%d\n", outPos, m);

      output_array[len-nIter-1]=input_array[outPos];

      for(int i=outPos; i

      input_array[i]=input_array[i+1];

      num--;

      print_array(num, input_array);

      }

      }

      voidmain()

      {

      int input_array[]={3,1,2,4};

      int output_array[4]={0};

      array_iterate(4, input_array, 7,output_array);

      print_array(4, output_array);

      }

      27.統計數字出現的次數,最大次數的統計出來

      舉例:

      輸入:323324423343

      輸出:3,6

      #include

      #include

      #include

      int main()

      {

      char*num="323324423343";

      inta[10]={0};

      intlen=strlen(num);

      inti,j,temp,count=0,maxnum=0;

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

      for(i=0;i

      {

      temp=num[i]-'0';

      a[temp]++;

      }

      inttemp1=a[0];

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

      {

      if(a[j]!=0)

      {

      count++;

      temp1=(temp1>a[j])?temp1:a[j];

      printf("%d%d\n",a[j],j);

      }

      }

      printf("數字出現次數為:%d\n",count);

      printf("最大次數為:%d\n",temp1);

      return0;

      }

      28. .字符串首字母轉換成大寫

      舉例:

      輸入:this is a book

      返回:This Is A Book

      #include

      #include

      #include

      int main()

      {

      charinput[]="this is a book";

      charoutput[256]={'\0'};

      int i,len;

      len=strlen(input);

      printf("變換前的字符串為:%s\n",input);

      for(i=0;i

      {

      if(input[0]!='')

      input[0]-=32;

      if(input[i]=='')

      input[i+1]-=32;

      output[i]=input[i];

      }

      printf("變換后的字符串為:%s\n",output);

      }

      29. 子串分離

      題目描述:

      通過鍵盤輸入任意一個字符串序列,字符串可能包含多個子串,子串以空格分隔。請編寫一

      個程序,自動分離出各個子串,并使用’,’將其分隔,并且在最后也補充一個’,’并將子

      串存儲。

      如果輸入“abc def gh i d”,結果將是abc,def,gh,i,d,

      要求實現函數:

      voidDivideString(const char *pInputStr, long lInputLen, char *pOutputStr);

      【輸入】 pInputStr: 輸入字符串

      lInputLen: 輸入字符串長度

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

      #include

      #include

      #include

      #include

    更多相關文章推薦閱讀:

    1.2016年華為認證考試題庫

    2.2016年華為hcie認證考試題庫

    3.2016年華為認證認證試題(筆試)

    4.2016年華為認證考試題及答案

    5.2016年華為上機考試題

    6.2016年華為HCDA認證考試題庫

    7.2016年華為筆試題及及答案

    8.2016年華為筆試面試題及答案

    9.2016年華為HCDA認證考試筆試題及答案

      void DivideString(const char *pInputStr, long lInputLen, char*pOutputStr)

      {

      int cnt;

      const char*p=pInputStr;

      while(*p!=NULL)

      {

      if(*p!=' ')

      { cnt = 0;

      *pOutputStr++ = *p++;

      }

      else

      { cnt++;

      p++;

      if(cnt==1)

      *pOutputStr++ = ',';

      }

      }

      *pOutputStr++ = ',';

      *pOutputStr = '\0';

      }

      void main()

      {

      char *str = "abcdef gh i d";

      long len =strlen(str);

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

      //char outstr[100];

      DivideString(str,len,outstr);

      printf("%s",outstr);

      printf("\n");

      }
     

    更多相關文章推薦閱讀:

    1.2016年華為認證考試題庫

    2.2016年華為hcie認證考試題庫

    3.2016年華為認證認證試題(筆試)

    4.2016年華為認證考試題及答案

    5.2016年華為上機考試題

    6.2016年華為HCDA認證考試題庫

    7.2016年華為筆試題及及答案

    8.2016年華為筆試面試題及答案

    9.2016年華為HCDA認證考試筆試題及答案

    【華為認證考試題庫】相關文章:

    華為認證考試簡介09-22

    華為認證考試地址07-26

    2016年華為HCDA認證考試題庫07-16

    2016年華為hcie認證考試題庫06-29

    華為認證HCIE考試心得06-25

    華為HCIE認證考試流程06-23

    華為認證:HCNA考試心得09-20

    華為Enterprise Communication認證考試大綱05-30

    華為認證考試報名流程10-13

    主站蜘蛛池模板: 国产精品亚洲精品日韩已方| 99久久99久久精品国产片| 99久久久精品免费观看国产| 热综合一本伊人久久精品| 久久99国产精品久久久| 中文字幕精品亚洲无线码一区| 四虎成人精品免费影院| 精品无码国产自产拍在线观看| 久久93精品国产91久久综合| 青青青青久久精品国产| 婷婷五月深深久久精品| 国内精品免费久久影院| 久久99国产精品99久久| 日产精品99久久久久久| 久久国产精品免费一区二区三区| 992tv精品视频tv在线观看| 亚洲精品字幕在线观看| 久久亚洲精品无码观看不卡| 国产99视频精品免费视频76| 99久久这里只有精品| 无码国内精品人妻少妇蜜桃视频| 精品无人区无码乱码毛片国产| 四虎国产精品永久地址99新强| 97久久精品无码一区二区| 四虎国产成人永久精品免费 | 少妇伦子伦精品无码STYLES| 久久久久99精品成人片| 99久久精品免费国产大片| 精品久久一区二区三区| 国产精品国色综合久久| 精品人妻人人做人人爽 | 精品乱子伦一区二区三区| 91精品国产综合久久香蕉| 四虎最新永久在线精品免费| 国产精品青草久久久久婷婷| 国产精品一二三区| 国产精品久久久久9999| 97精品人妻系列无码人妻| 精品调教CHINESEGAY| 精品一区二区三区无码免费视频| 人人妻人人澡人人爽人人精品 |