/*
 * Solution to Problem 3 (C++)
 * 13th Annual CS Programming Contest
 * WCU Dept of Math and CS
 * Copyright 2002 , All Rights Reserved
 *
 * Problem Statement:
 * Pattern Detection.
 * You are given two sequences of characters of length five. 
 * You are to see if the characters in the two sequences are
 * following the same pattern.
 *
 * Having the same pattern is not the same as having the exact
 * same sequence of characters. Thus, you can not just compare
 * to see if the two arrays have the same characters at the
 * same index positions. However, if one array has a particular
 * character at two different indexes then the other array must
 * have at the same two indexes have a common character (which
 * may be different than the common character in the first array).
 * Also, if one array has different characters at two indexes,
 * then the second array must at those two indexes have different
 * characters. Otherwise, the two arrays are not following the
 * same pattern.
 *
 * This solution simply in code checks whether the two properties
 * specified above are true about the two sequences. In particular,
 * nested loops are used where the outer loop steps through all
 * the index values. The inner loop steps through all the index
 * values after the current outer loop index value. If the two 
 * index values have the same element in the first array, then 
 * they must also have the same element in the second array. If
 * the two index values have different elements in the first array,
 * then the two index values must have different elements in the
 * second array. If these properties are always true, then the
 * two arrays are following the same pattern.
 */

#include <iostream.h>

const int NUM_ELTS = 5;

bool samePattern(char array1[], char array2[])
{
  bool match = true;
  for (int index1 = 0; index1 < NUM_ELTS; index1++) 
    for (int index2 = index1 + 1; index2 < NUM_ELTS; index2++) 
    {
      if ((array1[index1] == array1[index2]) && (array2[index1] != array2[index2]))
        match = false;
      if ((array1[index1] != array1[index2]) && (array2[index1] == array2[index2]))
        match = false;
    }
  return match;
}

int main()
{
  int  index;
  char array1[NUM_ELTS]; 
  char array2[NUM_ELTS]; 

  cout << "Each sequence has five characters." << endl;
  cout << "Please enter the first character sequence: ";
  for (index = 0; index < NUM_ELTS; index++) {
      cin >> array1[index];
  } 
  cout << "Please enter the second character sequence: ";
  for (index = 0; index < NUM_ELTS; index++) {
      cin >> array2[index];
  } 
  
  if (samePattern(array1, array2))
    cout << "They two sequences have the same pattern." << endl;
  else
    cout << "They two sequences do not have the same pattern." << endl;
}

