No.6 同花顺判定
#include <iostream>
using namespace std; class card {
public : int num; int pattern; card* next = NULL ; card ( ) { } ; void set_card ( char n, int p) { num = n; pattern = p; }
} ; void swap ( int & a, int & b) { int temp; temp = a; a = b; b = temp;
} class set { card* head = NULL ; card* tail = NULL ;
public : set ( ) { } ; void insert ( card* temp) { if ( head == NULL ) { head = tail = temp; } else { tail- > next = temp; tail = temp; } } void sort ( ) { for ( card* temp = head; temp != tail; temp = temp- > next) { for ( card* curr = temp- > next; curr != NULL ; curr = curr- > next) { if ( temp- > num > curr- > num) { swap ( temp- > num, curr- > num) ; } } } } bool check ( ) { bool n = 1 ; card* curr = this - > head; for ( ; curr!= tail- > next; curr = curr- > next) { if ( curr- > pattern != this - > head- > pattern) { n = 0 ; } } return n; } bool judge ( ) { this - > sort ( ) ; bool n2 = 1 ; bool n1 = 1 ; for ( card* curr = head; curr != tail; curr = curr- > next) { if ( ( curr- > next- > num - curr- > num) != 1 ) { n1 = 0 ; } } if ( head- > num == 1 ) { head- > num = 14 ; this - > sort ( ) ; for ( card* curr = head; curr != tail; curr = curr- > next) { if ( ( curr- > next- > num - curr- > num) != 1 ) { n2 = 0 ; } } } return ( n1 || n2) ; }
} ; int main ( ) { int num; int pattern; set S; for ( int i = 0 ; i < 5 ; i++ ) { cin >> num >> pattern; card* temp = new card ( ) ; temp- > set_card ( num, pattern) ; S. insert ( temp) ; } if ( S. check ( ) == 1 ) { if ( S. judge ( ) == 1 ) { cout << "Yes!" << endl; } else { cout << "NO!" << endl; } } else { cout << "NO!" << endl; } return 0 ;
}