Esempio n. 1
0
int main(int argc, char** argv){
   
   /* Start the program off by having the user input a string and then check if it is a palindrome or not. */
   checkpalindrome();

   /* For the case where the input was a palindrome */
   if( begin == middle && palcheck == 1 ){
	  printf("\"%s\"\nWhat you entered above is a palindrome.\nYou will be shown three other examples of palindromes now.\n", text);
                 printf("Please enter a string no longer than 100 characters for the examples:\n");
                 gets(userchar); /* Save user's input for generating 3 other palindromes */
                 while( userchar[length2] != '\0' )
                    length2++;

                 /* Call palexample 3 times to generate 3 more examples of palindromes */
                 palexample();
                 palexample();
                 palexample();

   } /* End if statement for the case where it is a palindrome */

   /* For the case where the input was not a palindrome. */
   if( begin != middle && palcheck == 2 ){

                 printf("Please enter a string no longer than 100 characters for the examples:\n");
                 gets(userchar); /* Save user's input for generating 3 other palindromes */
                 while( userchar[length2] != '\0' )
                    length2++;

                 /* Generate 3 more examples of palindromes, but original needs to be fixed first */
                 notpalindrome();
                 palexample();
                 palexample();

   } /* End if statement for the case where it is NOT a palindrome */

   return (EXIT_SUCCESS); /* End of program */

}
char* markParalindromes(int index, int array_size, int list_size, char* words, short* word_indexes, int num_of_processes, int& new_size)
{
	// create array of max amount of words
	// this is worst case where it assumes 
	// all words are NOT palindrome
	char* new_words = new char[array_size];
	// start of word marker
	int start = -1;
	// end of word/start of next work markers
	int end = -1;
	// loop list of when each word starts using cyclic partioning
	// loop will start at the value from myid and increment by the number 
	// of processors doing the job
	for (int i = index, k = 0; i < list_size; i += num_of_processes)
	{
		// at index of list, getstart of word
		start = word_indexes[i];
		// end of word is start of next word NOT INCLUDING this element
		end = word_indexes[i + 1];
		// check if current word based off index is a plaindrome or not
		// this is for it not being a palindrome
		if (!checkpalindrome(start, end, words))
		{
			// loop this range of the word and add it to new array
			for (int j = start; j < end; j++)
			{
				// increase the number of words
				new_size++;
				// put char at pos j into new array at pos k
				new_words[k++] = words[j];
				//****assume \0 also gets copied*****
			}
		}
	}
	// return new char array of words that are not palindromes
	return new_words;
}