题解 | #字符串排序# MAP自带排序

字符串排序

https://www.nowcoder.com/practice/dfeed0e0e4624814b122265e859783b2

一开始想到了使用MAP,但是c++不知道怎么遍历MAP

#include <iostream>
#include <map>

using namespace std;

int main(){
	int n;
	while(cin >> n){
		getchar();
		map<int,string> str;
		for(int i = 0;i < n;i ++){
			string s;
			getline(cin,s);
			if(s == "stop"){
				break;
			}
			int size = s.size();
			str[size] = s;
		}
		map<int,string>::iterator it;
		for(it = str.begin();it != str.end();it ++){
			cout << it->second << endl;
		}
	}	
	return 0;
}
全部评论

相关推荐

酷酷的喜马拉雅山:感觉这比一直在初筛不动的好多了
点赞 评论 收藏
分享
karis_aqa:和hr没关系,都是打工的
点赞 评论 收藏
分享
评论
点赞
1
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务