排序字符串

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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值