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;
}
运行结果显示如下
相关推荐
小王C语言11 小时前
Qt常用控件:多元素控件,纵向列表,表格控件,树状控件
开发语言·qt
fanruitian11 小时前
python 可视化 panda seaborn matplotlib.pyplot
开发语言·python·matplotlib
jnrjian12 小时前
delete file shell 让 AI 写脚本
服务器·开发语言
傅科摆 _ py12 小时前
DP,贪心,堆和栈,二分力扣复习
开发语言·python·算法
kiracrimson12 小时前
栈与队列容器:适配器、deque 与 priority_queue
开发语言·c++·适配器模式
北冥you鱼12 小时前
Go 语言 CRUD 实战:从接口设计到真实业务场景
开发语言·后端·golang
Shaoshing13 小时前
LeetCode100 42.接雨水
java·算法·leetcode
郭小李13 小时前
springmvc 拦截器
java·开发语言·前端
web打印社区13 小时前
Chrome-kiosk-printing能上生产吗
开发语言·前端·javascript·chrome·websocket
域限奇点访客13 小时前
用AI生成问卷的网站怎么选?看题目录入结构、题型映射和生成后的校验
算法