C++ //练习 10.36 使用find在一个int的list中查找最后一个值为0的元素。

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

练习 10.36 使用find在一个int的list中查找最后一个值为0的元素。

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

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

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

    cout<<"Numbers: ";
    for(auto l : lst){
        cout<<l<<" ";
    }
    cout<<endl;

    auto res = find(lst.crbegin(), lst.crend(), 0);
    cout<<*res<<endl;

    return 0;
}
运行结果显示如下
相关推荐
http阿拉丁神猫3 小时前
Go语言入门笔记:从基础到开发环境搭建(二)
开发语言·笔记·golang
不会就选b4 小时前
C++补充部分(一)--lambda 表达式
开发语言·c++
Pniubi7 小时前
HashMap的扩容和树化边界
java·开发语言
gCode Teacher 格码致知9 小时前
Pandas教学-17:Series与Dataframe的关系
开发语言·python·pandas
发量惊人的中年网工9 小时前
分公司访问总部ERP慢怎么办?SD-WAN组网的排查与验收要点
服务器·开发语言·php
下页、再停留9 小时前
【C#桌面客户端系列学习-15】生成可视化图表之折线图、柱状图、饼状图
开发语言·c#
ShineWinsu9 小时前
对于JavaScript:操作元素的解析
开发语言·前端·javascript·面试·web·dom·元素
罗西的思考10 小时前
【Agentic RL】Dressage Staleness 控制深度分析
人工智能·算法·机器学习
quaer10 小时前
弗洛伊德算法--判圈法寻找环的入口O(n) O(1)
数据结构·算法
益莱储中国11 小时前
深度解析:RF 实验室从 5G迈向 6G 的过程中保持技术领先与设备升级的路径
开发语言·php