List of first knowledge (for HW)

Source: Internet
Author: User

Jeremy recently learned the concept of pointers and lists, and linked lists can be implemented using structs. He knew that there was a link list called a circular link list such as 1->2->3->4->5->1 (where the first 1 and the last 1 were the same).

After the mid-term exam, the teacher let Jeremy do a student's performance statistics, Jeremy want to use the structure to achieve a simple loop linked list to complete. He plans to read student numbers and grades, such as student number 1, grade B, student number 2, Grade A ...

This program needs to implement the following functions:

For example, there are 4 students, their grades are: "A", "3 B", "1 C", "1 D", their relationship is "a", "3 B", "Nine a", "Nine a", "seven".

The function that the program needs to implement is when enter a student number, output a classmate's rank, for example input 3, should output a, input 12 should output d.

When the number of entries in these students appear several times, the first time the output of the student's class, such as: "A", "B", "1", "D", should be output D

If the number is not found, the output is not

There are other pit Daddy places please remind each other in the comment area, and Mail ta, thank you.


Input


The first act two integers num and m,num represent the total number of students, and m represents the input number.

The following num lines, each line containing an integer representing the school number and a character representing the grade

Output

Grade level of previous classmates (line change)

Input
3 2

1 A

2 b

3 C

Output

A

The linked list template is as follows:

typedef struct node *link;

typedef struct Node {

int student_num;

Link next;

}node;

Although you can use the array to complete, but hope that students can master how to write the list and structure, the future written interview will have a great opportunity to use.

I'm using an array of structs, though not linked lists, but I can learn quite a lot.

1#include <stdio.h>2 structStu {3     intA;4     Charb//can provide convenience for open arrays or provide classification5 };6     7 intMain () {8     inti, Num, m;9     structStu haha[10000];//structs can be used to open an array, there can be many different types of variables, and can be divided into a number of variablesTenscanf"%d%d", &num, &m); One      for(i =1; I <= num; i++) { Ascanf"%d%c", &AMP;HAHA[I].A, &haha[i].b);//This can be used, note the space between%d and%c, according to the input of the topic must have, otherwise%c will be read into a space -     } -      for(i =1; I <= num; i++) { the         if(m = = haha[1].a) { -printf"%c\n", haha[num].b); -              Break; -}Else if(HAHA[I].A = =m) { +printf"%c\n", Haha[i-1].b); -              Break; +         } A     } at     return 0; -}

Standard answer

List of first knowledge (for HW)

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: info-contact@alibabacloud.com 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.