题解 | #扑克牌大小#

扑克牌大小

https://www.nowcoder.com/practice/0a92c75f5d6b4db28fcfa3e65e5c9b3f

#include <iostream>
#include<string>
#include<algorithm>
using namespace std;
string FindMaxCard(const string&line)
{
    //先查找是否存在大小王
    int pos=line.find("joker JOKER");
    if(pos!=-1)
    {
        return "joker JOKER";
    }
    //分割两张牌统计牌张数
    pos=line.find('-');
    string card1=line.substr(0,pos);
    string card2=line.substr(pos+1);
    int cnt1=count(card1.begin(),card1.end(),' ')+1;
    int cnt2=count(card2.begin(),card2.end(),' ')+1;
    //拿到第一张牌
    string first1=card1.substr(0,card1.find(' '));
      string first2=card2.substr(0,card2.find(' '));
    //同类型的牌比较第一张大小即可
    if(cnt1==cnt2)
    {  //将牌的大小进行简单的映射用来比较大小关系
        string tem="3 4 5 6 7 8 9 10 J Q K A 2 j";
        if(tem.find(first1)>tem.find(first2))
        {
            return card1;
        }
        else 
        {
          return card2;
        }
    }
    //如果张数不相等用来判断是否有炸弹
     if(cnt1==4)
      {
        return card1;
      }
   else if(cnt2==4)
   {
    return card2;
   }
   return "ERROR";
    
}
int main() {
      string line;
      while(getline(cin,line))
      {
        string ret=FindMaxCard(line);
        cout<<ret<<endl;
      }
return 0;
    }


全部评论

相关推荐

昨天 18:37
门头沟学院 Java
点赞 评论 收藏
分享
07-15 14:14
门头沟学院 Java
7.10投递7.15感谢信
投递地平线等公司7个岗位
点赞 评论 收藏
分享
06-02 15:53
阳光学院 Java
点赞 评论 收藏
分享
吴offer选手:下午mt一来就告警说项目来不及,估计明天拿了权限就要参与开发了 已老实
实习生的蛐蛐区
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务