字符串全排列定义.pdfVIP

  • 0
  • 0
  • 约2.01千字
  • 约 3页
  • 2021-12-02 发布于福建
  • 举报
字符串全排列 (permutation) 问题:给定字符串 S,生成该字符串的全排列。 方法 1:依次从字符串中取出一个字符作为最终排列的第一个字符,对剩余字符组成的字符串生 成全排列,最终结果为取出的字符和剩余子串全排列的组合。 #include iostream #include string using namespace std; void permute1(string prefix, string str) { if(str.length() == 0) cout prefix endl; else { for(int i = 0; i str.length(); i++) permute1(prefix+str[i], str.substr(0,i)+str.substr(i+1,str.length())); } } void permute1(string s) { permute1(,s); } int main() { //method1, unable to remove duplicate

文档评论(0)

1亿VIP精品文档

相关文档