暑假作业里有一道题一点头绪也没有,求帮忙
2018-08-30 14:08
程序代码:#include <iostream>
#include <algorithm>
#include <iterator>
#include <string>
using namespace std;
int main( void )
{
size_t n;
string buf[20];
// 输入
cin >> n;
copy_n( istream_iterator<string>(cin), n, buf );
// 排序
sort( buf, buf+n, [](const string& a, const string& b){return a+b>b+a;} );
// 输出
copy( buf, buf+n, ostream_iterator<string>(cout,"") ) = "\n";
}
2018-08-30 14:44
2018-08-30 14:47
2018-08-30 14:50
程序代码:#include <iostream>
#include <algorithm>
#include <iterator>
#include <string>
using namespace std;
bool cmp( const string& a, const string& b )
{
return a+b > b+a;
}
int main( void )
{
size_t n;
string buf[20];
// 输入
cin >> n;
for( size_t i=0; i!=n; ++i )
cin >> buf[i];
// 排序
sort( buf, buf+n, &cmp );
// 输出
for( size_t i=0; i!=n; ++i )
cout << buf[i];
cout << endl;
}
2018-08-30 14:51
2018-08-30 14:56
2018-08-30 15:09
2018-08-30 15:47
2018-09-18 19:31
2018-09-18 20:19