Machine Test-The composition of 5 cards

Source: Internet
Author: User



A deck of cards to send five cards to you: let you judge the composition of the number:
There are several situations:
1: Four: Four cards of the same value (regardless of the color of the card)
2: Three bands with one pair
3: Three cards with two different values
4: Two pairs
5: Shun Zi including 10,j,q,k,a
6: Nothing at all
7: Only one pair.



C


#include <iostream>#include <string>#include <cstdlib>using namespace STD;intcmpConst void*a,Const void*B) {return*(int*) a-* (int*) b;}intMain () {stringStrCin>>str;intFlagintnum[5],m=0; for(intI=0; I<str.size () &&m<5; i++) {if(str[i]>=' 2 '&&str[i]<=' 9 ') num[m++]=str[i]-' 0 ';Else if(str[i]==' 1 '&&str[i+1]==' 0 ') {num[m++]=Ten;        i++; }Else if(str[i]==' J '|| str[i]==' J ') num[m++]= One;Else if(str[i]==' Q '|| str[i]==' Q ') num[m++]= A;Else if(str[i]==' K '|| str[i]==' K ') num[m++]= -;Else if(str[i]==' A '|| str[i]==' A ') num[m++]= -;Else{cout<<"Input Error"<<endl;return 0; }} qsort (num,5,sizeof(int), CMP);if(num[0]==num[3]|| num[1]==num[4]) flag=1;Else if((num[0]==num[2]&&num[3]==num[4])|| (num[2]==num[4]&&num[0]==num[1])) flag=2;Else if((num[0]==num[2]&&num[3]!=num[4])|| (num[2]==num[4]&&num[0]!=num[1])|| num[1]==num[3]) flag=3;Else if((num[0]==num[1]&&num[2]==num[3])|| (num[0]==num[1]&&num[3]==num[4])|| (num[1]==num[2]&&num[3]==num[4])) flag=4;Else if(num[0]==num[1]|| num[1]==num[2]|| num[2]==num[3]|| num[3]==num[4]) flag=7;Else if(num[4]-num[0]==4) flag=5;Elseflag=6;cout<<flag<<endl;return 0; }


Java


ImportJava.util.Arrays;ImportJava.util.Scanner; Public  class pukenum {  Public Static void Main(string[] args) {Scanner s =NewScanner (system.in); String str = s.nextline ();intFlagint[]num=New int[5];intm=0; for(intI=0; I<str.length () &&m<5; i++) {if(Str.charat (i) >=' 2 '&&str.charat (i) <=' 9 ') Num[m++]=str.charat (i)-' 0 ';Else if(Str.charat (i) = =' 1 '&&str.charat (i+1)==' 0 ') {num[m++]=Ten;            i++; }Else if(Str.charat (i) = =' J '|| Str.charat (i) = =' J ') num[m++]= One;Else if(Str.charat (i) = =' Q '|| Str.charat (i) = =' Q ') num[m++]= A;Else if(Str.charat (i) = =' K '|| Str.charat (i) = =' K ') num[m++]= -;Else if(Str.charat (i) = =' A '|| Str.charat (i) = =' A ') num[m++]= -;Else{System.out.println ("Input Error");return; }} arrays.sort (num);if(num[0]==num[3]|| num[1]==num[4]) flag=1;Else if((num[0]==num[2]&&num[3]==num[4])|| (num[2]==num[4]&&num[0]==num[1])) flag=2;Else if((num[0]==num[2]&&num[3]!=num[4])|| (num[2]==num[4]&&num[0]!=num[1])|| num[1]==num[3]) flag=3;Else if((num[0]==num[1]&&num[2]==num[3])|| (num[0]==num[1]&&num[3]==num[4])|| (num[1]==num[2]&&num[3]==num[4])) flag=4;Else if(num[0]==num[1]|| num[1]==num[2]|| num[2]==num[3]|| num[3]==num[4]) flag=7;Else if(num[4]-num[0]==4) flag=5;Elseflag=6;    SYSTEM.OUT.PRINTLN (flag); }}





Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.



Machine Test-The composition of 5 cards


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.