SDUT 2527 斗地主

http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2527

思路 :以前的结训比赛,当时不会做,比完了也没去看,真是悲剧了。这次还是没做出来,因为很多细节问题并没有处理好。输入的时候要注意输入别的时候都是一个字符,但偏偏10不是,也因此容易产生错误,所以就要按字符串输入,然后再仔细一点这题就差不多了。

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>

using namespace std ;

char ch[110] ;
int sh[110] ;

int main()
{
    int n,m ;
    cin>>n ;
    for(int i = 0 ; i < n ; i++)
    {
        scanf("%d%*c",&m) ;
        int cnt = 0 ;
        for(int j = 0 ; j < m ; j++)
        {
            scanf("%s",ch) ;
            if(ch[0] >= '3'&&ch[0] <= '9')
            sh[cnt++] = ch[0]-'0' ;
            else if(ch[0] == '2')
            sh[cnt++] = 15 ;
            else if(ch[0] == '1')
            sh[cnt++] = 10 ;
            else if(ch[0] == 'J')
            sh[cnt++] = 11 ;
            else if(ch[0] == 'Q')
            sh[cnt++] = 12 ;
            else if(ch[0] == 'K')
            sh[cnt++] = 13 ;
            else if(ch[0] == 'A')
            sh[cnt++] = 14 ;
        }
        sort(sh,sh+cnt) ;
        for(int j = 0 ; j < cnt ; j++)
        {
            if(sh[j] >= 3&&sh[j] <= 10)
               j == 0 ? cout<<sh[j] : cout<<" "<<sh[j] ;
            else if(sh[j] == 11)
            j == 0 ? cout<<"J" : cout<<" J" ;
            else if(sh[j] == 12)
            j == 0 ? cout<<"Q" : cout<<" Q" ;
            else if(sh[j] == 13)
            j == 0 ? cout<<"K" : cout<<" K" ;
            else if(sh[j] == 14)
            j == 0 ? cout<<"A" : cout<<" A" ;
            else if(sh[j] == 15)
            j == 0 ? cout<<"2" : cout<<" 2" ;
        }
        cout<<endl ;
    }
    return 0 ;
}
View Code
原文地址:https://www.cnblogs.com/luyingfeng/p/3439447.html