zoukankan      html  css  js  c++  java
  • 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;

    }

  • 相关阅读:
    pycharm出现乱码
    Name-based virtual servers 给予名称的虚拟服务
    预建报为稳定版本
    nginx指令
    Module ngx_http_index_module nginx的首页模块
    我还在坚持中~
    手机端页面自适应解决方案—rem布局进阶版
    前端页面的适配使用rem换算
    js零碎知识汇总
    让input不可编辑
  • 原文地址:https://www.cnblogs.com/2014acm/p/3876450.html
Copyright © 2011-2022 走看看