<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                早上看到好友未央的一篇博文[《一道google的測試工程師筆試題》](http://www.itsbug.com/?p=208),內容如下: ~~~ 這是去年面試google測試工程師的一道題,題目如下: 設計一個函數,使用任意語言,完成以下功能: 一個句子,將句子中的單詞全部倒排過來,但單詞的字母順序不變。比如,This is a real world,輸出結果為world real a is this. ~~~ 他用C++很好的封裝了一個函數實現了此功能,如下,更多信息請訪問:[http://www.itsbug.com/?p=208](http://www.itsbug.com/?p=208) C++版本: ~~~ #include <iostream> #include <string.h> using namespace std; const char *Reverse(char *src); char *pDst=NULL; int main(int argc,char **argv) { cout << "please input your sentense:" << endl; char pSrc[100]; memset(pSrc,0,100); cin.getline(pSrc,100); cout << Reverse(pSrc) << endl; if (pDst != NULL)delete pDst; return 0; } const char *Reverse(char *pSrc) { char *pPos = pSrc; int iLen=strlen(pSrc); pDst = new char[iLen + 1]; memset(pDst,0,iLen+1); int iCurrentPos = 0; int iPrePos = 0; while (pPos) { if (pSrc[iCurrentPos] <= 'z' && pSrc[iCurrentPos] >= 'A') { iCurrentPos++; pPos ++; continue; } else { int iDistance =iCurrentPos-iPrePos; for (int i=0;i < iDistance;i++) { pDst[iLen - iCurrentPos+i] = pSrc[iPrePos+i]; } pDst[iLen-iCurrentPos-1]=pSrc[iCurrentPos]; iCurrentPos ++; } iPrePos = iCurrentPos; if (*pPos == '\0') { break; } else { pPos ++; } } return pDst; } ???memset(pDst,0,iLen+1); ???int iCurrentPos = 0; ???int iPrePos = 0; ???while (pPos) ???{ ???????if (pSrc[iCurrentPos] <= 'z' && pSrc[iCurrentPos] >= 'A') ???????{ ???????????iCurrentPos++; ???????????pPos ++; ???????????continue; ???????} ???????else ???????{ ???????????int iDistance =iCurrentPos-iPrePos; ???????????for (int i=0;i < iDistance;i++) ???????????{ ???????????pDst[iLen - iCurrentPos+i] = pSrc[iPrePos+i]; ???????????} ???????????pDst[iLen-iCurrentPos-1]=pSrc[iCurrentPos]; ???????????iCurrentPos ++; ???????} ???????iPrePos = iCurrentPos; ???????if (*pPos == '\0') ???????{ ???????????break; ???????} ???????else ???????{ ???????????pPos ++; ???????} ???} ???return pDst; } ~~~ 想了一下,如果此功能使用python來實現的話,可能比較方便,大致思路如下: 1. 將語句中的單詞提取出來放入list中; 2. 將list反轉; 3. 將反轉后的list輸出。 實現如下: python版本: ~~~ #!/usr/bin/env python # -*- coding: utf-8 -*- def str_reverse(str_src): ''' Function:返轉單詞,以空格或TAB鍵為間隔符 Input:NONE Output: NONE author: socrates blog:http://blog.csdn.net/dyx1024 date:2012-02-18 ''' #以空格為分隔符,將各單詞取出來存放在list中 str_dst = str_src.split() #反轉list str_dst.reverse() #返回反轉后的list對象 return str_dst if __name__ == '__main__': #遍歷list,輸出內容 for str_out in str_reverse(raw_input("please input your sentense:")): print str_out, ~~~ 測試: ~~~ [root@kevin python_test]# ./str_test.py please input your sentense:This is a real world world real a is This [root@kevin python_test]# ./str_test.py please input your sentense:中國 陜西 西安 西安 陜西 中國 [root@kevin python_test]# ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看