C代写:COMP112 Strings and Recursion

代写C基础作业,练习字符串和递归的用法。

Submission Instructions

  • Electronic submission is individual.
  • Exercise that will be submitted on time will receive a 5 points bonus.
  • Automatic extension of 3 working days will be given, but then the 5 points bonus won’t be given.
  • More than 3 days late exercises will not be accepted.
  • Appeals about wrong output won’t be accepted. You must use “diffMerge” before submitting.

Guide Lines

  • Please read the questions carefully before you start solving them.
  • You may assume correct input, unless otherwise specified.
  • Pay attention! The check will be automatic. So make sure you print in the exact way you’re required to. Check your output using the sample output you were given using “diffMerge”.
    • Check small/capital letters with the exercise examples and instructions.
    • Make sure you go down one line after every line being printed, even if it’s the last line.
    • Don’t print spaces before and after lines.
  • In this exercise you may only use functions from the “stdio.h” library (not from clrscr, delay).
  • Submit individually through the course website.
  • Submit file name format is: “[yourId].zip “ (zip, not rar or anything else).
    If your id is 110120180, then submit: 110120180.zip. the file will include:
    • File named: “student.txt” with your name, student ID and email.
    • Solution file “hw5q1.c”
    • Solution file “hw5q2.c”
  • Pay attention to the exercise F.A.Q.
  • You must submit everything with the correct names

Question 1: Strings

In this question you will solve the word search problem. Word search is a game where you have a two dimensional board with letters and a word you need to find.

The word can be written from left to right, from right to left, from the top down and from the bottom up.

For example:

If you have this matrix and the word “code” you can see that it can be found on the board, but the word “hello” cannot.

h y m s k
p c a w b
l o r h x
e d q l u
f e v m f

The size of the matrix is 10 by 10;

In order to read the matrix you can use the following function:

void readBoard(char board[10][10]){
  int i, j;
  for (i = 0; i < 10; i++) {
    for(j = 0; j < 10; j++) {
      scanf(" %c", &(board[i][j]));
    }
  }
}

Implement a program which reads the board (using the following function), and a word with up to 10 letters, and prints one of the following:
If the word was found in board[i][j], print “The word starts at board[%d][%d].\n”. Otherwise, if the word was not found, print “The word was not found.\n”.

Hint:
First, try and implement a function which returns 1 if it found the word in a given spot (given i, j) and given direction.

For examples check the given tests (there is one if the word is found and one if the word is not found).

Question 2: Recursion

In the current question you are not allowed to use loops!
In this question you need to write a recursive function, and call it one time from main. Write the recursive function int isEvenDigitsOdd(int a[], int n). Parameters: The function gets the array a and its size as inputs - you can assume that all the numbers in the array are positive integers (greater than zero), and that 0 doesn’t appear as a digit in the numbers in the array.

The function returns 1 if the number of even digits in the whole array is odd, and 0 otherwise.

Example:
For the following array the result will be 1:

The even digits are 4 8 4 2 8 6 6 6 6, so we have 9 even digits. 9 is odd so the return value is 1.

Requirements:

  • The function must be recursive and its signature should be exactly the one posted above.
  • You can change the array if you wish to.
  • You are not allowed to use strings.
  • You are not allowed to use loops.

Main function:
Write a main function that receives from the user a series of positive integer numbers until reading a 0 (zero is not one of the numbers in the series, and is used only to mark its end).

The program should check if the number of even digits in the number in the series is odd, if yes - print “YES!\n”, otherwise - print “NO…\n”.

If the first number you get is a zero, print “NO…\n” and exit your code.

Requirements:

  • You must use the function isEvenDigitsOdd.
  • The length of the series in not known ahead of time, but you can assume it divides by K. In our program K is defined to be 5. You should use a #define so your program could be changed and handle arrays of different sizes easily.
  • You can’t assume that the size of the array divides by 5 in the function isEvenDigitsOdd, and it should work for every input!

Example 1, for this series of numbers:

28 571 82462 52 4534 348 7 54 278 6663 0

The program should print:

YES!

Example 2, for this series of numbers:

22 571 82462 51 453 0

The program should print:

NO...

GOOD LUCK!!!