Advertisement
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];
- }
- for(int q=0;q<piece;q++){
- //循序檢查法
- if(list[q]=="A734"){
- cout<<q+1<<endl;
- }
- else{continue;}
- }
- sort(list,list+piece);
- //二分檢查法
- int times=1;
- int L=0,R=piece-1,M;
- while(L<=R){
- M=int((L+R)/2);
- if(list[M]=="A734"){
- break;
- }
- else if(list[M]>"A734"){
- R=M-1;
- times++;
- }
- else{
- L=M+1;
- times++;
- }
- }
- cout<<times<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement