Three Cards

Three Cards

Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 65535/32768K (Java/Other)
Total Submission(s) : 27   Accepted Submission(s) : 4

Font: Times New Roman | Verdana | Georgia

Font Size:

Problem Description

LaoPei and A q are good friends with Debugcool and they like playing cards.There is a way to play cards called Three cards, it is to say, all of the players will get three cards and only one will be the winner.
As everyone knows, each card has one of four suits and one of thirteen values:
• suits:clubs( C ),diamonds( D ),hearts( H )and spades( S ). They have no order.
&#8226; values:2 < 3 < 4 < …… < 9 < T( 10 ) < J < Q < K < A .
And there will be seven types of the three cards on the players' hands:
1) BaoZi:the three cards have the same values, for example:AH AS AD, 2C 2D 2S
2) TongHuaShun:the three cards have the same suit and their values increase by one, for example:7C 8C 9C, JH QH KH
3) JinHua:the three cards have the same suit
4) ShunZi:the three cards' values increase by one
5) DuiZi:there are two cards in the three cards have the same values
6) Other:the other situation except the above
The order:Baozi > TongHuaShun > JinHua > ShunZi > DuiZi > Other, if the players' cards have the same type, the values will be taken into count:on one hand, if the same type is DuiZi, the value of the two cards who have the same value will be compared firstly, if they have the same value, the other card's value will be compared. On the other hand, if the type is not DuiZi, from the biggest to the smallest will be compared successively, eg. QC 10C 9C < KC 4C 3C. If all value of the three cards of the players are the same, they tied. eg. QC 10C 9C = QH 10H 9H.

Input

The input contains several test cases, each test case will have only one line to represent the cards in LaoPei's hand and A q's hand, every line will have six cards, three for LaoPei and three for A q. Each card will consist of two parts:the values and the suits. For example:AS mean spades with value A. The cards will be separated by a space.

Output

For each test case, output a line containing the result of the game. If LaoPei's cards is bigger than A q's, output "LaoPei wins!", if A q's cards is bigger than LaoPei's, output "A q wins!", if they tied, output "Oh my god, who wins, Debugcool knows!"

Sample Input

AC AD AH KC KD KH
TD QD JD QC KC JC
2D 2C 5S 2S 2H 5C

Sample Output

LaoPei wins!
A q wins!
Oh my god, who wins, Debugcool knows!
#include<iostream>
#include<algorithm>
#include<fstream>
#include<string>
using namespace std;
char lie[15]={'0','2','3','4','5','6','7','8','9','T','J','Q','K','A'};
int p1[15];
int p2[15];
int flag1,flag2;
int x;
bool lmx(int a,int b)
{
 return a>b;
}
int main()
{
string s;
int i,k1,k2;
//ifstream cin("a.in.txt");
while(getline(cin,s))
{
 k1=0;k2=0;
 flag1=0;flag2=0;
 x=0;
 if(s[1]==s[4]&&s[1]==s[7])  flag1=1;
 if(s[10]==s[13]&&s[10]==s[16])  flag2=1;
 for(i=1;i<=13;i++)
 {
       if(s[0]==lie[i])  p1[k1++]=i;
    if(s[3]==lie[i])  p1[k1++]=i;
    if(s[6]==lie[i])  p1[k1++]=i;
    if(s[9]==lie[i])  p2[k2++]=i;
    if(s[12]==lie[i])  p2[k2++]=i;
    if(s[15]==lie[i])  p2[k2++]=i;
 }
 sort(p1,p1+3,lmx);
 sort(p2,p2+3,lmx);
    if(p1[0]==p1[2])
 {
  if(p2[0]==p2[2])
  {
   if(p1[0]>p2[0]) x=1;
   else if(p1[0]==p2[0]) x=0;
   else x=-1;
  }
  else x=1;
 }
    else if(flag1==1&&p1[0]-p1[2]==2)
 {
  if(p2[0]==p2[2])  x=-1;
  else if(flag2==1&&p2[0]-p2[2]==2)
  {
   if(p1[0]>p2[0])  x=1;
   else if(p1[0]==p2[0]) x=0;
   else x=-1;
  }
  else x=1;
 }
 else if(flag1==1)
 {
        if(p2[0]==p2[2])  x=-1;
        else if(flag2==1&&p2[0]-p2[2]==2)  x=-1;
  else if(flag2==1)
  {
   for(i=0;i<3;i++)
   {
    if(p1[i]>p2[i])  {x=1;break;}
                else if(p1[i]<p2[i]) {x=-1;break;}
   }
  }
  else x=1;
 }
 else if(p1[0]-p1[2]==2)
 {
  if(p2[0]==p2[2])  x=-1;
  else if(flag2==1&&p2[0]-p2[2]==2)  x=-1;
  else if(flag2==1)  x=-1;
  else if(p2[0]-p2[2]==2)
  {
   if(p1[0]>p2[0])  x=1;
   else if(p1[0]==p2[0]) x=0;
   else x=-1;
  }
  else x=1;
 }
 else if(p1[0]==p1[1]||p1[1]==p1[2])
 {
        if(p2[0]==p2[2])  x=-1;
   else if(flag2==1&&p2[0]-p2[2]==2)  x=-1;
  else if(flag2==1)  x=-1;
  else if(p2[0]-p2[2]==2) x=-1;
  else if(p2[0]==p2[1]||p2[1]==p2[2])
  {
   if(p1[0]==p1[1]&&p2[0]==p2[1])
   {
    if(p1[0]>p2[0])  x=1;
    else if(p1[0]<p2[0]) x=-1;
    else
    {
     if(p1[2]>p2[2])  x=1;
     else if(p1[2]>p2[2]) x=-1;
     else x=0;
    }
   }
   else if(p1[0]==p1[1]&&p2[1]==p2[2])
   {
    if(p1[0]>p2[1])  x=1;
    else if(p1[0]<p2[1]) x=-1;
    else
    {
     if(p1[2]>p2[1]) x=1;
     else if(p1[2]<p2[1]) x=-1;
     else x=0;
    }
   }
   else if(p1[1]==p1[2]&&p2[0]==p2[1])
   {
    if(p1[1]>p2[0])  x=1;
    else if(p1[1]<p2[0]) x=-1;
        else x=1;
   }
   else if(p1[1]==p1[2]&&p2[1]==p2[2])
   {
    if(p1[1]>p2[1]) x=1;
    else if(p1[1]<p2[1]) x=-1;
    else
    {
     if(p1[0]>p2[0]) x=1;
     else if(p1[0]<p2[0]) x=-1;
     else x=0;
    }
   }
  }
  else x=1;
 }
 else
 {
        if(p2[0]==p2[2])  x=-1;
  else if(flag2==1&&p2[0]-p2[2]==2)  x=-1;
  else if(flag2==1)  x=-1;
  else if(p2[0]-p2[2]==2) x=-1;
  else if(p2[0]==p2[1]||p2[1]==p2[2])  x=-1;
  else
  {
   for(i=0;i<3;i++)
   {
    if(p1[i]>p2[i]) {x=1;break;}
    else if(p1[i]<p2[i]) {x=-1;break;}
   }
  }
 }
 if(x==1)  cout<<"LaoPei wins!"<<endl;
 else if(x==-1)  cout<<"A q wins!"<<endl;
    else cout<<"Oh my god, who wins, Debugcool knows!"<<endl;
}
return 0;
}
posted @ 2012-10-31 17:26  forevermemory  阅读(277)  评论(0编辑  收藏  举报