当前位置: 代码迷 >> 综合 >> Q9.2
  详细解决方案

Q9.2

热度:31   发布时间:2024-01-15 21:20:14.0
#include <iostream>
#include <algorithm>
using namespace std;bool cmp(string a, string b)
{sort(&a[0], &a[0] + a.length());        //关于sort的用法 sort(&b[0], &b[0] + b.length());return a < b;
}int main(void)
{string s[] = {"axyz", "abc", "yzax", "bac", "zyxa", "fg", "gf"};sort(s, s + 7, cmp);for(int i = 0; i != 7; ++i)cout << s[i] << " ";cout << endl;return 0;
}

  相关解决方案