将输入的一行字符串排序(逆序)输出

3 views
Skip to first unread message

bruc...@gmail.com

unread,
Oct 19, 2005, 10:52:02 PM10/19/05
to 星星爱CPP
#pragma warning( disable: 4786 )
#include <iostream>
#include <string>
#include <vector>
#include <iterator>
#include <sstream>
#include <algorithm>
#include <functional>
using namespace std;

int main( void )
{
string line;
getline( cin, line );

vector<string> vs;
istringstream is( line );
copy( istream_iterator<string>(is), istream_iterator<string>(),
back_inserter(vs) );

sort( vs.begin(), vs.end(), greater<string>() );

copy( vs.begin(), vs.end(), ostream_iterator<string>(cout,"\n") );

return 0;
}

输入
This is an apple
输出
is
apple
an
This

SevenCat

unread,
Oct 20, 2005, 2:31:42 AM10/20/05
to 星星爱CPP
#include <string>
#include <algorithm>
#include <iostream>


int _tmain(int argc, _TCHAR* argv[])
{
std::string teststr("1234567890");
std::reverse(teststr.begin(),teststr.end());
std::cout<<teststr<<std::endl;
return 0;
}

SevenCat

unread,
Oct 20, 2005, 2:32:36 AM10/20/05
to 星星爱CPP
#include <string>
#include <algorithm>
#include <iostream>


int _tmain(int argc, _TCHAR* argv[])
{

std::string teststr;
std::getline(std::cin,teststr);

Reply all
Reply to author
Forward
0 new messages