stl------iterator迭代器与Vector

 Vector不定长数组

 

 

 例:http://newoj.acmclub.cn/contests/1258/problem/4

1926: 2018蓝桥杯培训-STL应用专题-day 2 vector作业题1

题目描述:

字符串有些是对称的,有些不是对称的,请将那些对称的字符串安从小到大的顺序输出,字符串先以长度论大小,如果长度相等,再以ASCII码值为排序标准;

输入:

输入一个n,表示接下来有n组字符串,串长<=256; n<=1000;

输出:

根据每个字符串,输出对称的那些串,并且要求按从小到大的顺序输出;

样例输入
7
123321
123454321
123
321
sdfsdfd
\dd\
121212
样例输出
123321
\dd\
123454321
#include <iostream>
#include <algorithm>
using namespace std;
struct node{
    string na;
    int len;
};
node num[1005];
bool cmp(node x,node y)
{
    if(x.len==y.len)
        return x.na<y.na;
    else
        return x.len<y.len;
}
int main()
{
    int n,k=0;
    string tmp,a;
    cin >> n;
    while(n--){
        cin >> a;
        tmp=a;
        reverse(tmp.begin(),tmp.end());     //对称,回文串,这函数用的方便!!!以前一直没这么想过!
        if(tmp==a)      //是对称串就存起来
        {
            num[k].na=a;
            num[k++].len=a.size();
        }
    }
    sort(num,num+k,cmp);
    for(int i=0;i<k;i++)
        cout << num[i].na << endl;
}
原文地址:https://www.cnblogs.com/Cloud-king/p/8525491.html