文章

211

粉丝

1

获赞

1178

访问

75.0k

头像
查找第K小数 题解:
P1383 北京邮电大学
发布于2026年3月14日 16:13
阅读数 290

#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	while(cin >> n){
		map<int,int> mp;
		while(n--){
			int x;
			cin >> x;
			mp[x] = 1;
		}
		int k;
		cin >> k;
		// 遍历map,找第k小的数
        int count = 0;
        for (auto it = mp.begin(); it != mp.end(); ++it) {
            count++;
            if (count == k) {
                cout << it->first << endl;
                break;
            }
        }
	}	
	return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发