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;
}
运行结果显示如下
相关推荐
lueluelue472 小时前
LeetCode:链表
算法·leetcode·链表
隐积3 小时前
3.1.7.Qt容器大家族(3):QVariant——万能盒子
开发语言·qt
橘子汽水1685 小时前
Leetcode 23,543合并K个升序链表,二叉树的直径
算法·leetcode·链表
huameinan狮子5 小时前
Adaboost算法原理与计算实例
算法
Tri_Function5 小时前
动态规划DP1(c++)
c++
别怪我很水5 小时前
API中提供了VelocityTracker类用于计算触摸事件MotionEvent的速度,而其内部默认使用的方法就是最小二乘法,本 ...
算法·gitee·最小二乘法
名字还没想好☜6 小时前
Next.js ‘use client‘ 到底加在哪:Server/Client Components 边界与常见报错
开发语言·前端·javascript·react·next.js
初级代码游戏7 小时前
iOS开发 Swift 速记1:变量和基本数据类型
开发语言·ios·swift
酷在前行8 小时前
【R生态】PERMANOVA 进阶实战:距离选择、PERMDISP、两两比较与受限置换(保姆级教程)
开发语言·r语言