• vector


    #include <vector>
    #include <iostream>
    #include <cstdio>
    #include <cctype>
    using namespace std;
    typedef long long ll;
    vector < ll > vec;
    inline ll read () {
        ll x=0,f=1;
        char ch=getchar();
        while(!isdigit(ch)) {
            if(ch=='-') f=-1;
            ch=getchar();
        }
        while(isdigit(ch)) {
            x=(x<<1)+(x<<3)+(ch^48);
            ch=getchar();
        }
        return x*f;
    }
    int n;
    signed main() {
        n=read();
        for(register int i=1; i<=n; i++) vec.push_back(read());
        for(vector < ll >::iterator it=vec.begin(); it!=vec.end(); it++) cout<<*it<<' ';
        cout<<endl;
        for(register int i=0;i<=vec.size()-1;i++) cout<<vec[i]<<' ';//如果这样输出 下标必须为0开始
        return 0;
    //vec.push_back(x) 把x元素插入到vector末尾
    //vec.insert(pos,elem);在pos位置插入elem元素拷贝 返回新数据位置
    //vec.insert(pos,n,elem);在pos位置插入n个elem元素
    //vec.insert(pos,beg,end);在pos位置插入beg-end的元素
    //vec.clear();清空vector
    //vec.erase(beg,end); 清空beg-end的数字
    //vec.erase(pos);清空pos位置
    }

     例题

    #include <bits/stdc++.h>
    #define rep(i,j,n) for(register int i=j;i<=n;i++)
    #define Rep(i,j,n) for(register int i=j;i>=n;i--)
    #define low(x) x&(-x)
    using namespace std ;
    typedef long long LL ;
    const int inf = INT_MAX >> 1 ;
    inline LL In() { LL res(0) , f(1) ; register char c ;
    #define gc c = getchar()
        while(isspace(gc)) ; c == '-' ? f = - 1 , gc : 0 ;
        while(res = (res << 1) + (res << 3) + (c & 15) , isdigit(gc)) ;
        return res * f ;
    #undef gc
    }
    
    int m , n ;
    vector < int > vec ;
    inline void Ot() {
        m = In() ; n = In() ;
        int ans(0) ;
        rep(i,1,n) {
            int x = In() ;
            if(find(vec.begin() , vec.end() , x) == vec.end()) {
                vec.push_back(x) ;
                ans ++ ;
            }
            if(vec.size() > m) vec.erase(vec.begin()) ;
        }
        cout << ans << endl ;
    }
    signed main() {
    //  freopen("testdata.txt","w",stdout) ;
        return Ot() , 0 ;
    }
    P1540
    不存在十全十美的文章 如同不存在彻头彻尾的绝望
  • 相关阅读:
    Linux IO模型
    linux进程管理
    shell之判断文件是否存在
    python之hashlib模块(MD5校验)
    Docker实现退出container后保持继续运行的解决办法
    Pycharm上python运行和unittest运行两种执行方式解析
    Linux du与df命令的差异
    Linux lsof命令详解
    Selenium执行完毕未关闭chromedriver/geckodriver进程的解决办法(java版+python版)
    理解Python中的闭包
  • 原文地址:https://www.cnblogs.com/qf-breeze/p/10341208.html
Copyright © 2020-2023  润新知