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. 華為上機(jī)題目之最長(zhǎng)回文

        時(shí)間:2020-11-12 09:28:30 華為認(rèn)證 我要投稿

        2016年華為上機(jī)題目之最長(zhǎng)回文

          本文為同學(xué)們分享的是華為上機(jī)題目之最長(zhǎng)回文,希望對(duì)大家復(fù)習(xí)華為認(rèn)證有所幫助!

          一段字符串中提取最長(zhǎng)的回文長(zhǎng)度:

          淺顯易懂的`想法就是假設(shè)任何一個(gè)位置的字符為回文中心,進(jìn)行兩個(gè)方向的擴(kuò)散,進(jìn)而提取最長(zhǎng)回文。

          這是最樸素的想法:

          代碼如下:

          1 #include

          2 #include

          3 using namespace std;

          4

          5 char str[100]="abbbbaaa";

          6

          7

          8 //如果是回文長(zhǎng)度是偶數(shù)個(gè)

          9 int getMidtwoNum(char* s,int length,int index)

          10 {

          11 int re=1;

          12 int t=index,b=index+1;

          13 while(t>=0&&b

          14 {

          15 if(t==index)

          16 re++;

          17 else

          18 re+=2;

          19 b++;

          20 t--;

          21 }

          22 return re;

          23 }

          24

          25 //回文長(zhǎng)度是奇數(shù)個(gè)

          26 int getMidoneNum(char* s,int length,int index)

          27 {

          28 int re=1;

          29 int t=index-1,b=index+1;

          30 while(t>=0&&b

          31 {

          32 re+=2;

          33 b++;

          34 t--;

          35 }

          36 return re;

          37 }

          38

          39 int getLhw(char* s)

          40 {

          41 int length=strlen(s);

          42 int re=0;

          43 int temp=0;

          44 for(int i=0;i

          45 {

          46 temp=max(getMidoneNum(s,length,i),getMidtwoNum(s,length,i));

          47 if(temp>re)

          48 {

          49 re=temp;

          50 }

          51 }

          52 return re;

          53 }

          54 int main()

          55 {

          56 cout<

          57 getchar();

          58 }

        【2016年華為上機(jī)題目之最長(zhǎng)回文】相關(guān)文章:

        1.華為上機(jī)試題匯總

        2.華為Java上機(jī)考試題

        3.華為C語言上機(jī)試題及答案

        4.2016年華為上機(jī)考試題

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

        6.2016年華為認(rèn)證C/C++筆試題目

        7.CAD上機(jī)實(shí)習(xí)報(bào)告

        8.華為認(rèn)證簡(jiǎn)介

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