高中生程式解題系統:排列最大值
題目連結 http://zerojudge.tw/ShowProblem?problemid=b051 。 此題改寫 C++語言sort 的比較函數comp即可。 程式碼: # include <iostream> # include <string> # include <algorithm> using namespace std ; bool cmp ( const string & s1, const string & s2) { return (s1 + s2).compare(s2 + s1) > 0 ; } int main () { int n; while ( cin >> n) { string s[n]; for ( int i = 0 ; i < n; i++) cin >> s[i]; sort(s, s+n, cmp); for ( int i = 0 ; i < n; i++) cout << s[i]; cout << endl ; } return 0 ; } 若您覺得文章寫得不錯,請點選文章上的廣告,來支持小編,謝謝。