007 字串,字串

來源:互聯網
上載者:User

007 字串,字串
假設你有一個isSubstring函數,可以檢測一個字串是否是另一個字串的子串。 
給出字串s1和s2,只使用一次isSubstring就能判斷s2是否是s1的旋轉字串, 

請寫出代碼。旋轉字串:"waterbottle"是"erbottlewat"的旋轉字串。

簡答題:

#include <iostream>#include <string>bool isSubstring(const std::string& vSource, const std::string& vSubStr){if (vSource.find(vSubStr) != std::string::npos) return true;return false;}bool isRotate(const std::string& vLeft, const std::string& vRight){if (vLeft.length() != vRight.length()) return false;return (vLeft+vLeft, vRight);}int main(){std::cout << isRotate("dayup", "upday") << std::endl;return 0;}



字串常量“\007”為何不合法

\0是字串結束符,\是逸出字元,\去掉或是寫成\\
 
字元斜杠'\'與字串"\007"是合法常量吧

都不合法
把'\'改成'\\'就合法了
把"\007"改成'\007'合法了

逸出字元 逸出字元的意義

\n 斷行符號換行
\t 橫向跳到下一製表位置
\\ 反斜線符\
\' 單引號符'
\" 雙引號符"
\ddd 1~3位八位元所代表的字元
\xhh 1~2位十六進位數所代表的字元
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.