请问c哪错了。。。

#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,x=0,y=0;
    string str;
     bool flag=0;
    cin>>n;
    while(n--){
        cin>>str;
        for(int i=0;i<str.size();i++)
          if(str[i]=='N'||str[i]=='n')
          x++;
           else if(str[i]=='Y'||str[i]=='y')
          y++;
    }
    if(x>=str.size()/2)
    cout<<"pmznb";
     else   flag=1;
    if(y>=str.size()/2)
    cout<<"lyrnb";
     else flag=1;
        if(x==y==str.size()/2)
            cout<< "pmznb"<<"lyrnb";         
      if(flag=2) cout<<"wsdd";      
    return 0;
}
全部评论
首先,题主可能没有真正理解题意,因为在题意的叙述中,答案只可能是一个,当满足第一个答案时,其余的直接不执行了。其次while循环的大括号位置不对,他因该是在return 0之上结束,而且那个x和y颠倒了位置,标志位不需要使用 #include<bits/stdc++.h> using namespace std; int main(){     int n;     cin>>n;     while(n--){              string str;         cin>>str;         int n,x=0,y=0;         for(int i=0;i<str.length();i++)         {             if(str[i]=='N'||str[i]=='n')           x++;           if(str[i]=='Y'||str[i]=='y')           y++;         }     if(y>=(str.length()/2))     cout<<"pmznb"<<endl;         else     if(x>=(str.length()/2))     cout<<"lyrnb"<<endl;       else cout<<"wsdd"<<endl;     }     return 0; }
3 回复
分享
发布于 2019-12-09 11:34
谢谢
点赞 回复
分享
发布于 2019-12-10 23:55
小红书
校招火热招聘中
官网直投

相关推荐

点赞 评论 收藏
转发
点赞 收藏 评论
分享
牛客网
牛客企业服务