题解 | #扑克牌大小#

扑克牌大小

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;
    }


全部评论

相关推荐

不愿透露姓名的神秘牛友
09-18 14:26
点赞 评论 收藏
分享
程序员牛肉:小牛肉来也! 基本破不了局了,我给你的建议是适当放弃秋招,投递大厂的日常实习之后赶明年的春招。 在没有实习的情况下,你的项目经历给面试官的作用就是提供提问点方便面试官来提问八股以及场景题而已。因此你现在简历的写法不太对,要着重突出项目中使用的技术点,而不是像你现在这个写的很宽泛。 最好是“基于xxxx技术解决了xxxx问题,解决了xxxx边缘场景问题”。最好是这样写,方便面试官对你的简历进行提问。 最后的最后,问题其实不在你。今年的秋招确实比较寒冬一点,所以找不到是正常的。要做好打持久战的准备。
Java学习交流
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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