#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;
int n;
cin >> n;
getchar();
while (n--)
{
getline(cin, s);
t = s;
//反转字符串,用来判断字符是否对称
reverse(t.begin(), t.end());
if (t == s)
{
v.push_back(s);
}
}
sort(v.begin(), v.end(), Comp);
for (int i = ; i<v.size(); i++)
{
cout << v[i] << endl;
}
return ;
}

vector可以当作一个动态数组用,遍历的时候也可以当做是一个数组,因为可以随机访问,所以可以使用sort等algorithm里的函数

注意:下次如果遇到关于字符串倒转问题时首先考虑翻转reverse;

还有(1)?(2):(3)的意思,1式为判断,true返回2式,flase返回3式

?:,reverse,vector的基本小结的更多相关文章

  1. vector的用法小结(待补全

    1.vector的好处 支!持!删!除! 节!省!内!存! 2.一点基础的小操作 ①插入操作:v.push_back(x) 在尾部插入元素x: ②删除操作 : v.erase(x)删除地址为x的元素 ...

  2. [LeetCode] Reverse Words in a String II 翻转字符串中的单词之二

    Given an input string, reverse the string word by word. A word is defined as a sequence of non-space ...

  3. LeetCode: Reverse Words in a String && Rotate Array

    Title: Given an input string, reverse the string word by word. For example,Given s = "the sky i ...

  4. C++易错小结

    C++ 11 vector 遍历方法小结 方法零,对C念念不舍的童鞋们习惯的写法: void ShowVec(const vector<int>& valList) { int c ...

  5. 【LeetCode】186. Reverse Words in a String II 解题报告 (C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 每个单词单独翻转+总的翻转 日期 题目地址:https ...

  6. LeetCode记录(1)——Array

    1.Two Sum naive 4.Median of Two Sorted Arrays 找两个已排序数组的中位数 直接数可以过,但很蠢,O(m+n)时间 class Solution { publ ...

  7. [LeetCode] “全排列”问题系列(二) - 基于全排列本身的问题,例题: Next Permutation , Permutation Sequence

    一.开篇 既上一篇<交换法生成全排列及其应用> 后,这里讲的是基于全排列 (Permutation)本身的一些问题,包括:求下一个全排列(Next Permutation):求指定位置的全 ...

  8. Careercup - Microsoft面试题 - 6282862240202752

    2014-05-11 03:56 题目链接 原题: Given an integer array. Perform circular right shift by n. Give the best s ...

  9. ###STL学习--标准模板库

    下面进行STL的学习.希望能了解标准模板库中的常用容器,迭代器,可以自由运用STL以提高编写代码的效率.下面的内容我想以知识点为总结,不再像<Effective C++>那样以章节进行总结 ...

随机推荐

  1. Java基础_0206:方法的定义与使用

    方法的基本概念 方法的主要功能是封装可以执行的一段代码,这样不仅可以进行重复调用,更可以方便的实现代码的维护,而本次使用的方法定义语法如下所示. public static 返回值类型 方法名称(参数 ...

  2. 分页插件通用处理,以asp.net mvc为例

    Model: public class PaggerModel { public PaggerModel() { BarSize = ; } public PaggerModel(int total, ...

  3. Discuz!X 3.4 前台任意文件删除漏洞复现

    Discuz!X 3.4 前台任意文件删除漏洞复现 参考链接: http://www.freebuf.com/vuls/149904.html http://www.freebuf.com/artic ...

  4. java--GC Root有哪些

    GC管理的主要区域是Java堆,一般情况下只针对堆进行垃圾回收.方法区.JVM栈和Native栈不被GC所管理,因而选择这些非堆区的对象作为GC roots,被GC roots引用的对象不被GC回收. ...

  5. [Docker]CentOS7通过rpm包安装Docker

    前几天写过一篇文章:[Docker]CentOS7下Docker安装教程,直接使用yum命令下载Docker即可.但是前提是你需要***,所以这篇文章来讲讲,如果不会***,该如何安装Docker. ...

  6. 【转】Python数据类型之“文本序列(Text Sequence)”

    [转]Python数据类型之“文本序列(Text Sequence)” Python中的文本序列类型 Python中的文本数据由str对象或字符串进行处理. 1.字符串 字符串是Unicode码值的不 ...

  7. ethtool 解决网卡丢包严重和网卡原理【转】

    转自:https://blog.csdn.net/u011857683/article/details/83758869 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog ...

  8. 出现警告“user1 不在 sudoers 文件中。此事将被报告。”

    linux中不是每个用户都有sudo权限. 在/etc/下有个文件sudoers 由此文件可知只有用户为sudo这个组的成员之后才能执行sudo命令 此时,我们查看用户user1的属性: 由此看出us ...

  9. UPS不间断电源工作原理简述

    原文地址:https://blog.csdn.net/uamix/article/details/52776297 一.定义 UPS即不间断电源,是将蓄电池(多为铅酸免维护蓄电池)与主机相连接,通过主 ...

  10. ubuntu 安装source insight3.5

    版本 ubuntu 16.04 在linux下安装 windows下程序,需要安装wine, wine 是 "“Wine Is Not an Emulator" 缩写. 1) 安装 ...