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;

    }

  • 相关阅读:
    KVM---利用 libvirt+qemu-kvm 创建虚拟机
    docker---安装docker
    Ubuntu---VIM 常用命令
    Ubuntu--- 安装VMware 报错 Build enviroment error!
    Ubuntu---不能打开 exfat 文件系统格式的 U盘解决方法
    Ubuntu---gedit 打开windows 下 .txt 文件乱码的解决方法
    MCS-51单片机的串行口及串行通信技术
    MCS-51单片机的定时器/计数器
    MCS-51单片机的中断系统
    计算机网络——网络层
  • 原文地址:https://www.cnblogs.com/2014acm/p/3876450.html
Copyright © 2011-2022 走看看