?:,reverse,vector的基本小结
#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的基本小结的更多相关文章
- vector的用法小结(待补全
1.vector的好处 支!持!删!除! 节!省!内!存! 2.一点基础的小操作 ①插入操作:v.push_back(x) 在尾部插入元素x: ②删除操作 : v.erase(x)删除地址为x的元素 ...
- [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 ...
- 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 ...
- C++易错小结
C++ 11 vector 遍历方法小结 方法零,对C念念不舍的童鞋们习惯的写法: void ShowVec(const vector<int>& valList) { int c ...
- 【LeetCode】186. Reverse Words in a String II 解题报告 (C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 每个单词单独翻转+总的翻转 日期 题目地址:https ...
- LeetCode记录(1)——Array
1.Two Sum naive 4.Median of Two Sorted Arrays 找两个已排序数组的中位数 直接数可以过,但很蠢,O(m+n)时间 class Solution { publ ...
- [LeetCode] “全排列”问题系列(二) - 基于全排列本身的问题,例题: Next Permutation , Permutation Sequence
一.开篇 既上一篇<交换法生成全排列及其应用> 后,这里讲的是基于全排列 (Permutation)本身的一些问题,包括:求下一个全排列(Next Permutation):求指定位置的全 ...
- Careercup - Microsoft面试题 - 6282862240202752
2014-05-11 03:56 题目链接 原题: Given an integer array. Perform circular right shift by n. Give the best s ...
- ###STL学习--标准模板库
下面进行STL的学习.希望能了解标准模板库中的常用容器,迭代器,可以自由运用STL以提高编写代码的效率.下面的内容我想以知识点为总结,不再像<Effective C++>那样以章节进行总结 ...
随机推荐
- python判断小数示例&写入文件内容示例
#需求分析: #1.判断小数点个数是否为1 #2.按照小数点分隔,取到小数点左边和右边的值 #3.判断正小数,小数点左边为整数,小数点右边为整数 #4.判断负小数,小数点左边以负号开头,并且只有一个负 ...
- 基于【字符】操作的IO接口:Writer、Reader
Reader public class BufferedReaderTest { public static void main(String[] args) throws IOException { ...
- 新eclipse 打开就版本的工作空间提示:
点击OK后,完美呈现 (因为本人的旧版本已经被我玩坏了,有些菜单已经打不开)
- Java HashMap、HashTable、TreeMap、WeakHashMap区别
1.HashMap不是线程安全,而HashTable是线程安全
- Struts2学习(二)
1.Struts2的Servlet的API的访问 1.1 完全解耦合的方式 ActionContext context = ActionContext.getContext( ); 通过conte ...
- k64 datasheet学习笔记3---Chip Configuration之Human machine interfaces
1.前言 本文主要概略讲述GPIO相关的内容 2.GPIO configuration 注: GPIO模块没有访问保护,因为他没有连接到peripheral bridge slot上,不受MPU保护 ...
- 使用jsencrypt(rsa加密方式)给js加密防被刷
加密步骤 1.需要加密的参数 * * ).toISOString().replace(/T/g, }Z/, ''); //使用本地时间,然后转换格式 2.js中引用jsencrypt.js文件,然后实 ...
- Centos 6.x/7.x yum安装php5.6.X(最新版)
鉴于Centos 默认yum源的php版本太低了,手动编译安装又有点一些麻烦,那么如何采用Yum安装的方案安装最新版呢.那么,今天我们就来学习下如何用yum安装php最新版. 1.检查当前安装的PHP ...
- Apollo 启动脚本解析
Apollo 启动脚本解析 sudo service docker start -- 是在ubuntu14.04中打开 在dev_start.sh脚本中会调用restart_map_volume.sh ...
- FreeSWITCH 增删模组
今天在尝试FreeSWITCH新功能时,遇到一个问题,就是该功能所需要的模组没有加载,导致写了好久的代码不能看到效果,让人很是忧伤啊! 再此,将FS模组增删的方法记录下,以方便遇到同样问题的童鞋. 具 ...