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. 華為認證考試題庫

        時間:2023-02-26 08:34:11 華為認證 我要投稿

        2016年華為認證考試題庫

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

        2016年華為認證考試題庫

          1.第一題的題目大概是輸入整型數(shù)組求數(shù)組的最小數(shù)和最大數(shù)之和,例如輸入1,2,3,4則輸出為5,當輸入只有一個數(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.求兩個長長整型的數(shù)據(jù)的和并輸出,例如輸入1233333333333333。。。 3111111111111111111111111.。。。,則輸出。。。。

          #include

          #include

          #include

          main()

          {

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

          char*sum;

          // inttemp;

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

          intlen_max,len_min;

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

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

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

          scanf("%s",num1);

          printf("輸入兩個長長整型數(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--) //實現(xià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)組成的字符串。請編寫一個字符串過濾程序,若字符串中出現(xiàn)多個相同的字符,將非首次出現(xiàn)的字符過濾掉。

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

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

          壓縮規(guī)則:

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

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

          要求實現(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ù)的加、減運算式,請編寫一個程序輸出運算結(jié)果字符串。

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

          補充說明:

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

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

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

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

          #include

          #include

          #include

          #include

          typedef struct Node

          {

          intdata;

          structNode *next;

        更多相關(guān)文章推薦閱讀:

        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; //使鏈表尾連接鏈表頭,形成循環(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ù)字(可能不止一個),輸出最后剩余數(shù)字個數(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個身高),比較身高差,選出身高差最小的兩個身高;若身高差相同,選平均身高高的那兩個身高;從小到大輸出;

          如 輸入 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個):\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. 刪除子串,只要是原串中有相同的子串就刪掉,不管有多少個,返回子串個數(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. 要求編程實現(xiàn)上述高精度的十進制加法。要求實現(xiàn)函數(shù):

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

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

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

          【輸出】result:保存加法計算結(jié)果字符串,如果結(jié)果為負,則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表示進位

          int cur_rs = 0; //表示result的當前位數(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) //如果還有進位未加上

          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';

        更多相關(guān)文章推薦閱讀:

        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("請輸入兩個整型數(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;

          }

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

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

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

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

          輸入:輸入10個整數(shù),取值0~100

          輸出:輸出及格線,10的倍數(shù)

          #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。每盞電燈由一個拉線開關(guān)控制。開始,電燈全部關(guān)著。

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

          輸入:電燈的數(shù)量

          輸出:亮著的電燈數(shù)量

          樣例輸入: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("請輸入燈的數(shù)量(1-65535):\n");

          scanf("%d",&n);

          result=GetLightLampNum(n);

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

          return0;

          }

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

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

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

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

          輸出:輸出最少經(jīng)過的站數(shù),含輸入的起點和終點,換乘站點只計算一次

          輸入樣例: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;

        更多相關(guān)文章推薦閱讀:

        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;

          // 打印各鄰接節(jié)點

          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. 字串轉(zhuǎn)換

          問題描述:

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

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

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

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

          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. 數(shù)組中數(shù)字都兩兩相同,只有一個不同,找出該數(shù)字:

          int findUnique(int* a, int len)

          {

          int i = 1;

          int temp =a[0];

          for(; i

          {

          temp= temp ^ a[i];

          }

          printf("%d", temp);

          }

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

          #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. 鏈表翻轉(zhuǎn)。給出一個鏈表和一個數(shù)k,比如鏈表1→2→3→4→5→6,k=2,則翻轉(zhuǎn)后2→1→4→3→6→5,若k=3,翻轉(zhuǎn)后3→2→1→6→5→4,若k=4,翻轉(zhuǎn)后4→3→2→1→5→6,用程序?qū)崿F(xiàn)

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

        更多相關(guān)文章推薦閱讀:

        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)

          { //鏈表逆轉(zhuǎn)

          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; //指向逆轉(zhuǎn)之后的尾部

          LinkList*pTempHead = NULL;

          pCur->value= 1;

          pPre= pCur; //創(chuàng)建初始鏈表

          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; /*沒做翻轉(zhuǎn)之前的頭部,變成了翻轉(zhuǎn)之后的尾部*/

          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. 鏈表相鄰元素翻轉(zhuǎn),如a->b->c->d->e->f-g,翻轉(zhuǎn)后變?yōu)椋篵->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;

          }

          //創(chuàng)建新鏈表

          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 // !!!分配內(nèi)存頭文件

          #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”的數(shù)輸出并排序

          2.輸入一行數(shù)字:123 423 5645 875 186523

          在輸入第二行:23

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

          結(jié)果即: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個字符串 和一個整數(shù)n, 把字符串M化成以N為單位的段,不足的位數(shù)用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++)

        更多相關(guān)文章推薦閱讀:

        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.將整數(shù)倒序輸出,剔除重復數(shù)據(jù)

          輸入一個整數(shù),如12336544,或1750,然后從最后一位開始倒過來輸出,最后如果是0,則不輸出,輸出的數(shù)字是不帶重復數(shù)字的,所以上面的輸出是456321和571。如果是負數(shù),比如輸入-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條件里面的“(”、“)”括號經(jīng)常出現(xiàn)不匹配的情況導致編譯不過,請編寫程序檢測輸入一行if語句中的圓括號是否匹配正確。同時輸出語句中出現(xiàn)的左括號和右括號數(shù)量,如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;

          }

          約瑟夫問題

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

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

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

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

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

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

          輸出數(shù)值出列順序為:2,3,1,4。

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

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

          【輸入】 int len:輸入數(shù)列的長度;

          int intput_array[]:輸入的初始數(shù)列

          int m:初始計數(shù)值

          【輸出】 int output_array[]:輸出的數(shù)值出列順序

          【返回】 無

          示例:

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

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

          解題思路:

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

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

          代碼實現(xiàn):

          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.統(tǒng)計數(shù)字出現(xiàn)的次數(shù),最大次數(shù)的統(tǒng)計出來

          舉例:

          輸入: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("數(shù)字出現(xiàn)次數(shù)為:%d\n",count);

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

          return0;

          }

          28. .字符串首字母轉(zhuǎn)換成大寫

          舉例:

          輸入: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”,結(jié)果將是abc,def,gh,i,d,

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

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

          【輸入】 pInputStr: 輸入字符串

          lInputLen: 輸入字符串長度

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

          #include

          #include

          #include

          #include

        更多相關(guān)文章推薦閱讀:

        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");

          }
         

        更多相關(guān)文章推薦閱讀:

        1.2016年華為認證考試題庫

        2.2016年華為hcie認證考試題庫

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

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

        5.2016年華為上機考試題

        6.2016年華為HCDA認證考試題庫

        7.2016年華為筆試題及及答案

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

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

        【華為認證考試題庫】相關(guān)文章:

        2016年華為hcie認證考試題庫08-30

        2016年Adobe認證考試Photoshop題庫08-24

        Photoshop認證考試題庫08-30

        IBM認證考試題庫06-16

        華為認證考試試題及答案08-22

        華為認證考試模擬卷及答案08-29

        Adobe Photoshop認證考試題庫08-24

        Adobe Illustrator認證考試題庫08-24

        Oracle OCP認證考試題庫05-18

        国产高潮无套免费视频_久久九九兔免费精品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>