• zjut 1208排列对称串


    排列对称串  Time Limit:1000MS  Memory Limit:32768K

    Description:

    很多字串,有些是对称的,有些是不对称的,请将那些对称的字串按从小到大的顺序输出。字串先以长度论大小,如果长度相同,再以ASCII码值为大小标准。

    Input:

    输入数据中含有一些字串(1≤串长≤256)。

    Output:

    根据每个字串,输出对称的那些串,并且要求按从小到大的顺序输出。

    Sample Input:

    123321
    123454321
    123
    321
    sdfsdfd
    121212
    \dd\
    

    Sample Output:

    123321
    \dd\
    123454321

    #include <cstdio>

    #include <iostream>

    #include <string>

    #include <set>

    #include <algorithm>

    #include <vector>

    using namespace std;

    bool Comp(const string &s1,const string &s2)

    {     return s1.length()!=s2.length()    ?       s1.length()<s2.length()  : s1<s2;      }

    int main()

    {  

       vector<string>v;  

       string t,s;   

      while (cin>>s)   

      {       

                    t=s;                                     //s 保存到 t ,,,,,  t 不会改变

                                                                     //反转字符串,用来判断字符是否对称      

       reverse(t.begin(),t.end());                  //对称-----反转

            if (t==s)                                             // 反转后的s------压栈进入  向量容器vector      

       {             v.push_back(s);         }  

      }

                                                               //    排序    

    sort(v.begin(),v.end(),Comp);  

                                                            //输出向量中的所有元素   

      for (int i=0;i<v.size();i++)  

                {                   cout<<v[i]<<endl;               }    

    return 0;

    }

  • 相关阅读:
    装饰复杂函数
    装饰器01
    闭包
    函数的嵌套定义
    名称空间
    函数的嵌套调用
    函数的对象
    形参
    实参
    形参与实参
  • 原文地址:https://www.cnblogs.com/2014acm/p/3876450.html
Copyright © 2020-2023  润新知