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;
}
运行结果显示如下
相关推荐
csdn_aspnet41 分钟前
C++ 3个有序点的方向(Orientation of 3 ordered points)
c++·算法
Felven1 小时前
C. Brr Brrr Patapim
c语言·开发语言
赤生云电竞1 小时前
GPU算力共享平台架构实践:任务分发与资源隔离的关键配置
算法·架构·gpu算力
小七在进步2 小时前
string的使用(2)
c++
路溪非溪2 小时前
python标准库使用总结
开发语言·python
青少儿编程课堂3 小时前
蓝桥杯·全国青少年信息素养大赛·电子学会Python/C++考级:折半搜索优化子集枚举(Meet in the Middle)解析
c++·python·算法·bfs·信息学竞赛
SomeOtherTime4 小时前
Rust 面向对象介绍(AI回答)
开发语言·python·rust
wo_jack4 小时前
C++ 入门笔记(十七):list 入门 —— 为什么 list 不能 sort?
数据结构·c++·面试·stl·list
zh_xuan4 小时前
kotlin常见面试题
开发语言·kotlin·面试题
Oneshot5 小时前
DLX(Dancing Links)算法详解:求解数独最快的算法
算法