zoukankan      html  css  js  c++  java
  • 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
    不存在十全十美的文章 如同不存在彻头彻尾的绝望
  • 相关阅读:
    为什么要用设计模式?先看看6大原则(一)
    git版本库的创建和yaf框架环境的部署
    laravel日常小问题
    Session store not set on request.
    phpstudy集成环境安装lavarel
    html中提交表单并实现不跳转页面处理返回值
    document load 与document ready的区别
    定时器优化
    放大镜
    子组件调用父组件的方法并传递数据
  • 原文地址:https://www.cnblogs.com/qf-breeze/p/10341208.html
Copyright © 2011-2022 走看看