Very simple simulation,

Source: Internet
Author: User

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
1 6 5 3
1 2
Sample Output

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,

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.