-
Notifications
You must be signed in to change notification settings - Fork 0
/
0104.cpp
73 lines (64 loc) · 1.32 KB
/
0104.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <iostream>
#include <string>
#include <vector>
using namespace std;
// 在此处补充你的代码
// typedef typename vector<int>::iterator it_int;
// typedef typename vector<string>::iterator it_string;
// template <typename T>
// class less<T>;
// template <typename T>
// class less{
// public:
// less(){}
// bool operator()(const T& x,const T& m){
// if(x < m) return true;
// else return false;
// }
// };
template <typename Init,typename T,typename OP>
Init FindFirstLess(Init s,Init e,T m,OP c_f){
auto it = s;
for(;it != e;++it)
if(c_f(*it,m)) return it;
return it;
}
int main()
{
int t;
cin >> t;
while(t--) {
int n ;
string type;
cin >> n >> type;
vector<int> vi;
vector<string> vs;
if( type == "N") {
int a,m;
for(int i = 0;i < n - 1; ++i) {
cin >> a;
vi.push_back(a);
}
cin >> m;
vector<int>::iterator p = FindFirstLess(vi.begin(),vi.end(),m,less<int>());
if( p!= vi.end())
cout << * p << endl;
else
cout << "Not Found" << endl;
}
else {
string a,m;
for(int i = 0;i < n - 1; ++i) {
cin >> a;
vs.push_back(a);
}
cin >> m;
vector<string>::iterator p = FindFirstLess(vs.begin(),vs.end(),m,less<string>());
if( p!= vs.end())
cout << * p << endl;
else
cout << "Not Found" << endl;
}
}
return 0;
}