1104 - I2P EECS 2016 HW10 Scoreboard

Time

2016/12/14 10:00:00 2016/12/21 09:00:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
10840 Check Palindrome
10839 Equivalent relation

10840 - Check Palindrome   

Description

Palindrome is a string that is identical to its reverse, like "level" or "aba".  Check whether a given string is a palindrome or not.
 

Note that

1.      This problem involves three files.

  • function.h: Function definition of isPalindrome.
  • function.c: Function describe of isPalindrome.
  • main.c: A driver program to test your implementation.

You will be provided with main.c and function.h, and asked to implement function.c.

2.     For OJ submission:

       Step 1. Submit only your function.c into the submission block. (Please choose c compiler) 

       Step 2. Check the results and debug your program if necessary.

function.h

#ifndef FUNCTION_H
#define FUNCTION_H
int isPalindrome(char *start, char *end);
#endif

main.c

#include <stdio.h>
#include <string.h>
#include "function.h"

int main()
{
        char str[5000];
        while (EOF != scanf("%s", str))
        {
                char *start = str;
                char *end = start + strlen(str) - 1;
                if (isPalindrome(start, end))
                {
                        printf("Yes\n");
                }
                else
                {
                        printf("No\n");
                }
        }
}

Input

The input consists of multiple lines. Each line contains a string.
The length of each string is less than 5000.  The number of test case is less than 100.

Output

For each test case, output "Yes" if it's a palindrome or "No" if it's not a palindrome in a line.

Sample Input  Download

Sample Output  Download

Partial Judge Code

10840.c

Partial Judge Header

10840.h

Tags

10401HW9



Discuss




10839 - Equivalent relation   

Description

There are N integer pointers, indexed from 0 to N-1 (N<100). Each pointer initially points to an integer of value 0.

There are two kinds of instructions. The instruction “S n k” is used to set the integer, which pointer n points to, to be k. For example, S 1 10 means that the integer that pointer 1 points to is set to 10. And the instruction “P n m” means that pointer n points to the integer that pointer m points. For example, P 2 1 means that pointer 2 points to the integer that pointer 1 points to. After P 2 1, pointer 2 and pointer 1 point to the same integer, which is pointed by pointer 1. 

Note that you don't have to change all the pointers if one pointer changes its target. The following table is an example. The instructions are P 1 2 and then P 2 3.  You do not have to change the target of pointer 1.

instruction

Description

P 1 2

Pointer 1 points to the integer that pointer 2 points to.

 

P 2 3

Pointer 2 points to the integer that pointer 3 points to.

And you don’t have to change the target of pointer 1.

Finally, output all the values that pointers 0 to N-1 point to in order.

Note that

1.      This problem involves three files.

  • function.h: Function definition of execInstruct.
  • function.c: Function describe of execInstruct.
  • main.c: A driver program to test your implementation.

You will be provided with main.c and function.h, and asked to implement function.c.

2.     For OJ submission:

       Step 1. Submit only your function.c into the submission block. (Please choose c compiler) 

       Step 2. Check the results and debug your program if necessary.

Hints:

main.c

#include <stdio.h>
#include "function.h"

#define SIZE 100

int main() {
        int *ptrArr[SIZE];
        int dataArr[SIZE] = {0};
        char inst;
        int dataNum, instNum;
        int param1, param2;
        int i;

        /* input */
        scanf("%d %d", &dataNum, &instNum);

        /* initialize the ptrArr */
        for (i = 0; i < dataNum; i++)
                ptrArr[i] = &dataArr[i];

        for (i = 0; i < instNum; i++) {
                scanf(" %c %d %d", &inst, &param1, &param2);

                execInst(ptrArr, inst, param1, param2);
        }

        /* output */
        for (i = 0; i < dataNum - 1; i++) {
                printf("%d ", *ptrArr[i]);
        }
        printf("%d", *ptrArr[i]);

        return 0;
}

function.h

#ifndef FUNCTION_H
#define FUNCTION_H

void execInst(int *ptrArr[], char inst, int param1, int param2);

#endif

Input

The first line contains two positive X and Y. X indicates the size of data. Y indicates that there are Y instructions needed to be done.

The next Y lines contain the instructions.

 

Output

All the values that pointers 0 to pointer N-1 point to in order. Each value is seperated by a blank ' '.

# Note that there is no '\n' at the end of the output.

Sample Input  Download

Sample Output  Download

Partial Judge Code

10839.c

Partial Judge Header

10839.h

Tags

10401HW9



Discuss