Problem Description:
很多字串,有些是对称的,有些是不对称的,请将那些对称的字串按从小到大的顺序输出。字串先以长度论大小,如果长度相同,再以ASCII码值为大小标准。
Input:
输入数据中含有一些字串(1≤串长≤256)
Output:
根据每个字串,输出对称的那些串,并且要求按从小到大的顺序输出。
Sample Input:
123321
123454321
123
321
sdfsdfd
121212
\\dd\\
Sample Output:
123321
\\dd\\
123454321
本题很简单,代码如下:#include<iostream>
#include<fstream>
#include<set>
#include<string>
#include<queue>
#include<set>
#include<iterator>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<numeric>
using namespace std;
bool isSym(string);
struct myCmp
{
bool operator()(const string& str1,const string& str2)
{
return (str1.length() != str2.length() ? str1.length() < str2.length() : str1 < str2);
}
};
int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("D:\\in.txt", "r", stdin);
freopen("D:\\out.txt", "w", stdout);
#endif
string str;
multiset<string, myCmp> coll;
while (cin >> str )
{
if (!isSym(str))
{
continue;
}
coll.insert(str);
}
copy(coll.begin(), coll.end(),ostream_iterator<string>(cout,"\n"));
return 0;
}
bool isSym(string str)
{
string ss = str;
reverse(ss.begin(), ss.end());
if (ss == str)
{
return true;
}
return false;
}