// Phil Dexheimer
// 7/23/02
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct card
{
 char rank;
 char suit;
};



//Returns true if B's rank is one greater than A's
bool bNextHigher(card &A, card &B)
{
 // Returns true only if B's rank directly follows A's.
 switch (A.rank)
  {
   case 'A' : return B.rank == '2';
   case '2' : return B.rank == '3';
   case '3' : return B.rank == '4';
   case '4' : return B.rank == '5';
   case '5' : return B.rank == '6';
   case '6' : return B.rank == '7';
   case '7' : return B.rank == '8';
   case '8' : return B.rank == '9';
   case '9' : return B.rank == 'T';
   case 'T' : return B.rank == 'J';
   case 'J' : return B.rank == 'Q';
   case 'Q' : return B.rank == 'K';
   case 'K' : return B.rank == 'A';
  }
 return false;
}

void main ()

{
 FILE *In = fopen("deck.in", "rt");
 char line[80];
 card deck[60];
 int longSS, longAS;
 int curSS, curAS;
 int i;

 // Read in one line at a time.
 while(fgets(line, sizeof(line), In))
  {

   // Initialize the first half of the deck.
   for(i=0;i<26;i++)
    {
     deck[i].rank = line[i*2];
     deck[i].suit = line[i*2+1];
    }

   // Initialize the second half of the deck.
   fgets(line, sizeof(line), In);
   for(i=0;i<26;i++)
    {
     deck[26+i].rank = line[i*2];
     deck[26+i].suit = line[i*2+1];
    }

   // Set all default lengths to 1.
   longSS = longAS = curSS = curAS = 1;

   // Process each card in order.
   for (i=1;i<=52;i++)
    {
     // Update current suit streak.	
     if (deck[i].suit == deck[i-1].suit)
       curSS++;
     else
       curSS = 1;

     // Update current ascending sequence.
     if (bNextHigher(deck[i-1], deck[i]))
       curAS++;
     else
       curAS = 1;

     // Update longest sequences seen so far, if necessary.
     if (curSS > longSS)
       longSS = curSS;
     if (curAS > longAS)
       longAS = curAS;

    }

   // Print out the lengths of these sequences.
   printf("Longest same-suit sequence: %d\n", longSS);
   printf("Longest ascending sequence: %d\n\n", longAS);

  }

 fclose(In);
}
