Problem Description
Welcome to Zhejiang University of Technology fourth session of the program design contest!
But wait a moment! The referee Joe said he had to answer his question correctly before he could see Pipi balloon Mm,kuku's balloon Gg.
Joe has 7 cards with a capital letter on each card, z,j,u,t,a,c,m. Now he's performing magic, swapping only two of the cards at a time. After the show, please point out the card containing the letter J. Input
The first line of positive integer n (1<=n<=1000) indicates that there is a subsequent n set of test data.
The first line of the integer m (0<=m<=1000) for each set of test data represents the M-exchange operation; the second line has m pairs of integers <x,y> represents the top-down, starting from 1 numbered x and y cards. At first, the top 7 cards were ZJUTACM, That is, the position of the J card is 2. Output
For each set of test data, the position of the output J card. Sample Input
2
2
1 6 5 3
1
1 2
Sample Output
2
1
It seems very difficult to get through, in fact, very simple. The normal method can be too. directly on the code.
#include <stdio.h>int main () { int n,i,t1,t2; scanf ("%d", &n); while (n--) { int sum=2; Let sum=2 represent the position of card 2 directly. int m; scanf ("%d", &m); for (i=1;i<=m;i++) { scanf ("%d%d", &t1,&t2); if (t2==sum) // equal then Exchange sum=t1; else if (t1==sum) sum=t2; ditto } printf ("%d\n", sum); Get the final position when you're done. }}
Very simple simulation,