C++ //练习 10.37 给定一个包含10个元素的vector,将位置3到7之间的元素按逆序拷贝到一个list中。

C++ Primer(第5版) 练习 10.37

练习 10.37 给定一个包含10个元素的vector,将位置3到7之间的元素按逆序拷贝到一个list中。

环境:Linux Ubuntu(云服务器)
工具:vim
代码块
cpp 复制代码
/*************************************************************************
	> File Name: ex10.37.cpp
	> Author: 
	> Mail: 
	> Created Time: Thu 14 Mar 2024 03:38:34 PM CST
 ************************************************************************/

#include<iostream>
#include<vector>
#include<list>
#include<algorithm>
#include<iterator>
using namespace std;

int main(){
    vector<int> number;
    int num;
    cout<<"Enter numbers: ";
    while(cin>>num){
        number.push_back(num);
        if(cin.get() == '\n'){
            break;
        }
    }

    cout<<"Vector numbers: ";
    for(auto n : number){
        cout<<n<<" ";
    }
    cout<<endl;

    list<int> lst;
    for(auto iter = number.crbegin() + 4; iter != number.crend() - 3; ++iter){
        lst.push_back(*iter);
    }
    cout<<"List numbers: ";
    for(auto l : lst){
        cout<<l<<" ";
    }
    cout<<endl;

    return 0;
}
运行结果显示如下
相关推荐
CoovallyAIHub18 小时前
语音AI Agent编排框架!Pipecat斩获10K+ Star,60+集成开箱即用,亚秒级对话延迟接近真人反应速度!
深度学习·算法·计算机视觉
木心月转码ing20 小时前
Hot100-Day14-T33搜索旋转排序数组
算法
会员源码网1 天前
内存泄漏(如未关闭流、缓存无限增长)
算法
颜酱1 天前
从0到1实现LFU缓存:思路拆解+代码落地
javascript·后端·算法
颜酱1 天前
从0到1实现LRU缓存:思路拆解+代码落地
javascript·后端·算法
CoovallyAIHub2 天前
Moonshine:比 Whisper 快 100 倍的端侧语音识别神器,Star 6.6K!
深度学习·算法·计算机视觉
CoovallyAIHub2 天前
速度暴涨10倍、成本暴降6倍!Mercury 2用扩散取代自回归,重新定义LLM推理速度
深度学习·算法·计算机视觉
CoovallyAIHub2 天前
实时视觉AI智能体框架来了!Vision Agents 狂揽7K Star,延迟低至30ms,YOLO+Gemini实时联动!
算法·架构·github
CoovallyAIHub2 天前
开源:YOLO最强对手?D-FINE目标检测与实例分割框架深度解析
人工智能·算法·github