?:,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++>那样以章节进行总结 ...
随机推荐
- JDK1.8HashMap源码解读
package java.util; import sun.misc.SharedSecrets; import java.io.IOException; import java.io.Invalid ...
- java实现打印前台页面
核心:用window自带方法 window.print(); 打印的范围:body里内容,只要在页面能显示出来,都打印 遇到的问题:打印按钮被一起打印出来了,url也别打印出来了 解决办法:在触发打印 ...
- call 和 apply 的区别
call 和 apply 都是为了改变某个函数运行时的 context 即上下文而存在的,换句话说,就是为了改变函数体内部 this 的指向.因为 JavaScript 的函数存在「定义时上下文」和「 ...
- 1Mybatis入门--1.1单独使用jdbc编程问题总结
1.1.1 jdbc程序 Public static void main(String[] args) { Connection connection = null; PreparedStatemen ...
- java在进程启动和关闭.exe程序
/** * @desc 启动进程 * @author zp * @date 2018-3-29 */ public static void startProc(String processName) ...
- canner CMS 系统 (公司在台湾) https://www.canner.io/
canner CMS 系统 (公司在台湾) https://www.canner.io/ https://github.com/Canner/canner 一种创新的CMS构建方式,采用 Nodej ...
- 深入理解 sudo 与 su 之间的区别【转】
深入理解 sudo 与 su 之间的区别 两个命令的最大区别是: sudo 命令需要输入当前用户的密码,su 命令需要输入 root 用户的密码.另外一个区别是其默认行为.sudo 命令只允许使用提升 ...
- while(cin>>n1>>n2)
这里有2个点, 1. while(cin>>n)用到了强制类型转换 2. 强调输入遇到-1则退出,说明要一直看是否输入了-1,并记录下来 #include <iostream> ...
- python3+requests库框架设计02-封装日志类
首先我们先来实现日志的功能,日志可以使用python3自带logging模块,不会的可以百度一下相关文章,也可以看我另外一篇文章Python3学习笔记24-logging模块 在封装日志类前,我们需要 ...
- python3之模块SMTP协议客户端与email邮件MIME对象
转载自https://www.cnblogs.com/zhangxinqi/p/9113859.html 阅读目录 1.smtplib模块的常用类与方法 2.处理邮件MIME 3.实例 (1)使用HT ...