全部评论 4

  • ?你有没有好好看 数组中有0吗

    2025-02-23 来自 广东

    0
    • 你应该特判0的情况

      2025-02-23 来自 广东

      0
    • 复制代码:

      #include<bits/stdc++.h>
      using namespace std;
      
      int main(){
          int n,a[1000000],m;
          cin>>n;
          for(int i=1;i<=n;i++){
              cin>>a[i];
          }
          cin>>m;
          while(m--){
              int b;
              cin>>b;
              //这里加特判?
              int x=lower_bound(a+1,a+1+n,b)-a;
              if(a[x]!=b ){   // 是不是在这里加特判
                  cout<<-1<<" ";
              }else{
                  cout<<x<<" ";
              }
              int y=upper_bound(a+1,a+n+1,b)-a-1;
              if(a[y]!=b){   // 还是在这里?
                  cout<<-1<<" ";
              }else{
                  cout<<y<<" ";
              }
              y+=1;
              if(a[y]>b){ // 或者是在这里?
                  cout<<y<<endl;
              }else{
                  cout<<-1<<endl;
              }
          }
          return 0;
      }
      

      在哪里特判呢

      2025-02-24 来自 上海

      0
    • 直接特判b==0就行

      2025-02-24 来自 广东

      0
  • 2025-02-23 来自 上海

    0
  • 2025-02-23 来自 上海

    0
  • 2025-02-23 来自 上海

    0
暂无数据

提交答案之后,这里将显示提交结果~

首页