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
| #include<bits/stdc++.h> using namespace std; const int maxn=100000+10; const int INF=2*int(1e9)+10; #define LL long long int cmd(int a,int b){ return a>b; } int main(){ int num[6]={1,2,4,7,15,34}; sort(num,num+6); int pos1=lower_bound(num,num+6,7)-num; int pos2=upper_bound(num,num+6,7)-num; cout<<pos1<<" "<<num[pos1]<<endl; cout<<pos2<<" "<<num[pos2]<<endl; sort(num,num+6,cmd); int pos3=lower_bound(num,num+6,7,greater<int>())-num; int pos4=upper_bound(num,num+6,7,greater<int>())-num; cout<<pos3<<" "<<num[pos3]<<endl; cout<<pos4<<" "<<num[pos4]<<endl; return 0; }
3 7 4 15 2 7 3 4
|