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;
}
运行结果显示如下
相关推荐
To_OC14 小时前
LC 1 两数之和:面试第一道必考题,暴力解法直接被面试官 pass
javascript·算法·leetcode
鱼鱼不愚与18 小时前
《原来如此 | 第01期:为什么导航软件能预测红绿灯倒计时?》
算法
博客180021 小时前
酷宝的使用方法,超好用的免费界面库,C++、MFC可用
c++·mfc·界面库·库来帮·酷宝
郝学胜_神的一滴1 天前
CMake 026:属性体系精讲、四大作用域全解 & 实战代码落地
c++·cmake
复杂网络1 天前
论最小 Agent 计算机的形态
算法
kisshyshy2 天前
🍦 雪糕、食堂、火车厢:三幅漫画吃透栈、队列与链表
javascript·算法
众少成多积小致巨2 天前
JNI (Java Native Interface) 技术手册中文参考指南
android·java·c++
猿人谷2 天前
不只是 CPU 阈值:STAR 如何用 GAT + Transformer 做容器级自动扩缩容?
人工智能·算法
复杂网络2 天前
Stable Diffusion 视觉大模型微调技术深度调研
算法