m0_60901238 2021-08-23 18:47 采纳率: 81.5%
浏览 32
已结题

谁先倒,编译错误的原因求解



#include<iostream>
using namespace std;
int main(){
    int i,a,b,N,Ahan[100],Ahua[100],Bhan[100],Bhua[100],sumA=0,sumB=0;
    cin>>a>>b;
    cin>>N;
    for(i=0;i<N;i++){
        cin>>Ahan[i]>>" ">>Ahua[i]>>" ">>Bhan[i]>>" ">>Bhua[i];
    }
    for(i=0;i<N;i++){
        if((Ahua[i]==(Ahan[i]+Bhan[i]))&&(Bhua[i]==(Ahan[i]+Bhan[i])))
            continue;
        if(Ahua[i]==(Ahan[i]+Bhan[i])){
            sumA++;
            a--;
            if(a<0){
                cout<<"A"<<endl;
                cout<<sumB;
             break;
            }
        }
        else if (Bhua[i]==(Ahan[i]+Bhan[i])){
            sumB++;
            b--;
            if(b<0){
                cout<<"B"<<endl;
                cout<<sumA;
             break;
            }
        }
    }
    return 0;
}

img
请问这个代码是哪里有问题导致总是执行错误呢?求解

  • 写回答

2条回答 默认 最新

  • StjpStjp 2021-08-23 18:48
    关注

    如果我的回答对你有帮助,请采纳谢谢

    
    #include<iostream>
    using namespace std;
    int main(){  
      int a,b,n,e,f,g,h,flag,d,l;
      scanf("%d%d%d",&a,&b,&n);
      d = a,l = b;
      while(n--){
        scanf("%d%d%d%d",&e,&f,&g,&h);
        if(f == (e + g) && h != (e + g))
          a--;
        if(f != (e + g) && h == (e + g))
          b--;
        if(a < 0){
          flag = 1;
          break;
        }
        if(b < 0){
          flag = 0;
          break;
        }
      }
      if(flag)
        printf("A\n%d\n",l - b);//!!!!
      else
        printf("B\n%d\n",d - a);//!!!!
      return 0;
    }
    

    或者是

    #include<bits/stdc++.h>
    using namespace std;
    #define ll long long
    #define inf 0x3f3f3f3f
    #define mem(a,b) memset(a,b,sizeof(a))
     
    int main()
    {
        int x,y,n,x1=0,y1=0,a,b,c,d,flag=0;
        cin>>x>>y;
        cin>>n;
        while(n--)
        {
            cin>>a>>b>>c>>d;
            if(flag)
                continue;
            if(a+c==b&&a+c!=d)
                x1++;
            if(a+c!=b&&a+c==d)
                y1++;
            if(x1>x&&!flag)
                flag=1;
            if(y1>y&&!flag)
                flag=2;
        }
        if(flag==1)
            cout<<"A"<<endl<<y1<<endl;
        else
            cout<<"B"<<endl<<x1<<endl; 
        return 0;
    }
    
    

    #include<iostream>
    #include<stdio.h>
    using namespace std;
     
    int main(){
        int count_a,count_b,n;
        int a_call[100],b_call[100],a_sweep[100],b_sweep[100];
        int count,call[100];
        cin>>count_a>>count_b;
        int count_a1 = count_a,count_b1 = count_b;
        cin>>n;
        //cout<<count_a1<<" "<<count_b1<<endl;
        for(int i=0;i<n;i++){
            cin>>a_call[i]>>a_sweep[i]>>b_call[i]>>b_sweep[i];
            call[i] = a_call[i]+b_call[i];
            //cout<<a_sweep[i]<<" "<<b_sweep[i]<<" "<<call[i]<<endl;
        }
        
        for(int i=0;i<n;i++){
            //cout<<i;
            //乙嬴 
            if(a_sweep[i]==call[i] && b_sweep[i]!=call[i]){
                count_a1--;
                
            }
            //甲嬴 
            else if(b_sweep[i]==call[i] && a_sweep[i]!=call[i]){
                count_b1--;
                
            }
            else{
                continue;
            }
            if(count_a1<0){
                printf("A\n");
                printf("%d",count_b - count_b1);
                break;
            }
            if(count_b1<0){
                printf("B\n");
                printf("%d",count_a - count_a1);
                break;
            }
            
        }
            
        return 0;
    }
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 8月31日
  • 已采纳回答 8月23日
  • 创建了问题 8月23日

悬赏问题

  • ¥30 c#打开word开启修订并实时显示批注
  • ¥15 如何解决ldsc的这条报错/index error
  • ¥15 VS2022+WDK驱动开发环境
  • ¥30 关于#java#的问题,请各位专家解答!
  • ¥30 vue+element根据数据循环生成多个table,如何实现最后一列 平均分合并
  • ¥20 pcf8563时钟芯片不启振
  • ¥20 pip2.40更新pip2.43时报错
  • ¥15 换yum源但仍然用不了httpd
  • ¥50 C# 使用DEVMOD设置打印机首选项
  • ¥15 麒麟V10 arm安装gdal