657 - CS135501_I2P2014_LAB_10 Scoreboard

Time

2014/12/08 15:50:00 2014/12/08 17:20:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
10319 Equivalent relation

10319 - 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.


Hints:

#include 
#define SIZE 100

int main(void)
{
    int *p[SIZE];
    int data[SIZE];
    int size;
    int i, n, m;
    char instruction;
    int n_assign;

    scanf("%d%d", &size, &n_assign);
    /* add your code here */

    for (i=0; i

 

Input

The first line contains two positive X and Y. X indicates the number of parameters. 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 answer is printed using ‘%d\n’.

Sample Input  Download

Sample Output  Download

Tags




Discuss