#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. [转] Linux shell判断文件和文件夹是否存在

    shell判断文件,目录是否存在或者具有权限 #!/bin/sh myPath="/var/log/httpd/" myFile="/var /log/httpd/acc ...

  2. mfc调用WPFDLL

    1.修改MFC项目属性支持CLR 2.打开vcxproj,修改<PropertyGroup Label="Globals"> <PropertyGroup Lab ...

  3. day 5 - 1 字典(dict)

    dict dict key 必须是不可变数据类型,可哈希value:任意数据类型 dict 优点:使用二分查询来搜索数据存储了大量的关系型数据特点:无序的 数据类型划分:可变数据类型,不可变数据类型不 ...

  4. JAVA知识笔记

    1.对于volatile修饰的变量,jvm虚拟机只是保证从主内存加载到线程工作内存的值是最新的.更详细介绍参考http://blog.csdn.net/libing13820393394/articl ...

  5. TensorFlow学习笔记之--[tf.clip_by_global_norm,tf.clip_by_value,tf.clip_by_norm等的区别]

    以下这些函数可以用于解决梯度消失或梯度爆炸问题上. 1. tf.clip_by_value tf.clip_by_value( t, clip_value_min, clip_value_max, n ...

  6. Linux安装JDK(tar)

    我以JDK1.8为例 ⒈下载 https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html ...

  7. 【转】python模块分析之logging日志(四)

    [转]python模块分析之logging日志(四) python的logging模块是用来写日志的,是python的标准模块. 系列文章 python模块分析之random(一) python模块分 ...

  8. Contains Duplicate I & III

    Contains Duplicate I Given an array of integers, find if the array contains any duplicates. Your fun ...

  9. A Light CNN for Deep Face Representation with Noisy Labels

    承接上一篇博客.该论文思路清晰,实验充分,这里大致写一些比较不错的idea.从标题就能看出本文的主要贡献:轻量.鲁棒.利用一个轻量CNN从大规模数据且含大量噪声中来学习一个深度面部表征. 直接谈谈贡献 ...

  10. 很清晰的解读i2c协议【转】

    转自:https://blog.csdn.net/weixin_41718085/article/details/79376823 转载:http://dpinglee.blog.163.com/bl ...