zoukankan      html  css  js  c++  java
  • ?:,reverse,vector的基本小结

     1 #include <cstdio>  //此代码为网上所复制
     2 #include <iostream>  
     3 #include <string>  
     4 #include <set>  
     5 #include <algorithm>  
     6 #include <vector>  
     7 using namespace std;
     8 
     9 bool Comp(const string &s1, const string &s2)
    10 {
    11     return s1.length() != s2.length() ? s1.length()<s2.length() : s1<s2;
    12 }
    13 int main()
    14 {
    15     vector<string> v;
    16     string t, s;
    17     int n;
    18     cin >> n;
    19     getchar();
    20     while (n--)
    21     {
    22         getline(cin, s);
    23         t = s;
    24         //反转字符串,用来判断字符是否对称  
    25         reverse(t.begin(), t.end());
    26         if (t == s)
    27         {
    28             v.push_back(s);
    29         }
    30     }
    31     sort(v.begin(), v.end(), Comp);
    32     for (int i = 0; i<v.size(); i++)
    33     {
    34         cout << v[i] << endl;
    35     }
    36     return 0;
    37 }

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

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

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

  • 相关阅读:
    任意进制间的转换
    判断线段相交 hdu 1086
    大数(高精度)加减乘除取模运算
    sqlserver2008透明书库加密
    数据库质疑
    sql2005 和sql2008 同时安装
    editrules
    sqlserver 表值函数
    sqlserver释放内存
    sql2008查看备份进度
  • 原文地址:https://www.cnblogs.com/kangdong/p/8722950.html
Copyright © 2011-2022 走看看