?:,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++>那样以章节进行总结 ...
随机推荐
- SqlServer_存储过程
1.查询全部数据 create proc stu1 as begin select * from Students end go exec stu1 2.根据姓名查询信息 --存储过程内部自带值cre ...
- 人人项目renren-security\git\renren-security的目录下的文件列表
\.git\config; \.git\FETCH_HEAD; \.git\HEAD; \.git\index; \.git\logs\HEAD; \.git\logs\refs\heads\mast ...
- Linux 学大纲
- Android RecyclerView 瀑布流滑动到最后自动加载更多
mRecycleView.setOnScrollListener(new RecyclerView.OnScrollListener(){ //用来标记是否正在向最后一个滑动,既是否向下滑动 bool ...
- Microsoft SQL - 数据库管理系统
数据库管理系统(Server Management Studio) SQL Server Management Studio是一个数据库管理系统软件,数据库可以看成是一个个存储数据的文件,而Manag ...
- Springboot 配置 ssl 实现HTTPS 请求 & Tomcat配置SSL支持https请求
SSL(Secure Sockets Layer 安全套接层),及其继任者传输层安全(Transport Layer Security,TLS)是为网络通信提供安全及数据完整性的一种安全协议.TLS与 ...
- Python-有关文件操作,函数调用几道练习:
1.写函数,,用户传入修改的文件名,与要修改的内容,执行函数,完成批了修改操作 2.写函数,计算传入字符串中[数字].[字母].[空格] 以及 [其他]的个数 3.写函数,判断用户传入的对象(字符串. ...
- Python3学习笔记33-正则表达式
学习文章传送门 正则表达式是用来匹配字符串的.只要符合规则的字符串.就可以认为匹配了.否则,这个字符串不合法. \d:可以匹配一个数字 ‘00\d’可以匹配001不能匹配00A \w:可以匹配 ...
- ubuntu16.04彻底删除nginx+php
1.1 删除nginx,–purge包括配置文件 sudo apt-get --purge remove nginx 1.2 自动移除全部不使用的软件包 sudo apt-get autoremove ...
- codeforces 38G - Queue splay伸展树
题目 https://codeforces.com/problemset/problem/38/G 题意: 一些人按顺序进入队列,每个人有两个属性,地位$A$和能力$C$ 每个人进入时都在队尾,并最多 ...