if( isset( $_POST["input"] )){
$my_array = $_POST["input"];
$my_array=strrev($my_array);
trim($my_array);
$my_array=explode("\n", $my_array);
natcasesort($my_array);
foreach($my_array as $key => $value)
echo strrev($value)." "; //print the array elements
}
?>
#include
#include
#include
#include
using namespace std;
////////////////////////////////////////
//
// Quick C++ Implementation or Corey White's
// "davinci sort" (which is a basic suffix
// sort).
//
// (c) 2007 Steven Pigeon
// released under GPL 2.0
//
////////////////////////////////////////
//
// introduces special operator< for suffix
// compares
//
struct less_rev: public binary_function
{
//////////////////////////////////////
//
// reverses a string
//
inline string _reverse(const string & a) const
{
string temp=a;
reverse(temp.begin(), temp.end() );
return temp;
}
//////////////////////////////////////
//
// compares two strings, in reverse
//
inline bool operator()(const string & a, const string & b) const
{
return _reverse(a) < _reverse(b);
}
};
////////////////////////////////////////
//
// Reads words from stdin/cin and reprint
// them suffix-sorted
//
int main()
{
vector words; // vector because sort needs random access
iterators
string read;
////////////////////////////
//
// reads from stdin/cin until
// eof
//
while ( getline(cin,read) )
words.push_back(read);
////////////////////////////
//
// uses standard sort algorithm
// but with less_rev
//
sort(words.begin(), words.end(), less_rev() );