这个是想仿leetcode上的一个链表题
原本意思是要用快慢指针的,但是由于题目给的是数组,就直接输出就完事了。
然而就是这样一个水题,还疯狂卡我的时间的,说我超时。
所以,以后还是多写scanf吧
#include <iostream>
#include <vector>
using namespace std;
int main(){
int k, x;
scanf("%d", &k);
vector<int> nums;
while(scanf("%d", &x) != EOF){
if(x < 0) break;
nums.push_back(x);
}
int t = nums.size();
if(k > t) cout<<"NULL"<<endl;
else cout << nums[t - k] << endl;
return 0;
}