日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > c/c++ >内容正文

c/c++

C++ map 中的reverse_iterator

發(fā)布時間:2024/9/30 c/c++ 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 C++ map 中的reverse_iterator 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

做了一個閩南師范大學(xué)OJ上的題,不想寫排序,用了一下reverse_iterator,反向遍歷容器

7006:學(xué)生成績排序


Problem Description

使用結(jié)構(gòu)數(shù)組存儲學(xué)生信息,信息包括了姓名name和成績score,按學(xué)生成績從高到低排序,并輸出。

?Input

輸入文件首先包含一個整數(shù)n(n<10),表示有n個學(xué)生,然后是n行學(xué)生記錄,一行代表一個學(xué)生,每個學(xué)生的name的長度小于15,且score為int型。

?Output

輸出按成績排序后學(xué)生的相關(guān)記錄,每個信息之間用兩個空格分隔,一個學(xué)生信息輸出一行,如下。

?Sample Input

6 GongJing 80 LiuNa 90 ZhouLi 86 ChenHai 95 SunYan 76 WangHong 98

?Sample Output

name:WangHong score:98 name:ChenHai score:95 name:LiuNa score:90 name:ZhouLi score:86 name:GongJing score:80 name:SunYan score:76



#include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include <iterator> #include <vector> #include<map> using namespace std; map<int,string>x; int main(){int a,n;string b;scanf("%d",&n);getchar();for(;n--;){cin>>b>>a;x[a]=b;}map<int,string>::reverse_iterator s=x.rbegin();map<int,string>::reverse_iterator d=x.rend();for(;s!=d;s++){cout<<"name:";cout<<s->second<<" score:"<<s->first<<"\n";}return 0; }

總結(jié)

以上是生活随笔為你收集整理的C++ map 中的reverse_iterator的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。