Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int main(){
- int piece,piece2;
- string check_number;
- cin>>piece;
- string list[piece];
- for(int i=0;i<piece;i++){
- cin>>list[i];
- }
- sort(list,list+piece);
- cin>>piece2;
- for(int q=0;q<piece2;q++){
- cin>>check_number;
- //二分搜尋法實作
- int found =0;
- int L=0,R=piece-1,M;
- while(L<=R){
- M=int((L+R)/2);
- if(list[M]==check_number){
- found =1;
- break;}
- else if(list[M]>check_number){
- R=M-1;}
- else{L=M+1;}
- }
- if(found==1) cout<<"Y\n";
- else cout<<"N\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment