11292 - Find/Revision   

Description

Given a bunch of data which are composed of each student’s name, height (cm), and weight (kg), in this problem, you are asked to design a simple system. The operation of the system is described as follows:

   Firstly, the instruction 'F' denotes “Find”, which means the system would print out the results containing the keyword for which the user wants to search in lexicographical order of students’ name. Noted that uppercase alphabet is different from lowercase alphabet when finding the keyword. Also, note that if there does not exist the data containing the keyword, the system would output “NOT FOUND”. Secondly, the instruction 'R' denotes “Revision”, which means the user can revise the ith raw/modified data accordingly. Note that if there are repeated student name after revision, the system would delete both sets of the data. Finally, the program terminates if the user enters character ‘E’ no matter in uppercase or lowercase. For instance,

Raw data

#      Name         Height      Weight
1      Cindy         163          49
2      Dennis       177          65
3      Ellie            170          60
4      Benny        185          75
5      Amy           172          70
 

Instruction

​R 2 Benny 180 70
R 2 Benson 177 70
F 70

  Since there are two students named Benny after revision, both of the data #2 and data #4 would be automatically deleted by the system. Then, the user uses 'R' to update the data and wants to find whether there is any data containing keyword “70”. If exist, output the results in lexicographical order of students’ name.

Modified data

#      Name        Height      Weight
1      Cindy         163          49
2      Benson      177          70
3      Ellie            170          60
4     
5      Amy            172          70

Output

Amy           172 70
Benson      177 70
Ellie            170 60

Note that

1.      This problem involves three files.

  • function.h: Function definition of Find_Revise.
  • function.c: Function describe of Find_Revise​.
  • 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:

function.h

#ifndef FUNCTION_H_INCLUDED
#define FUNCTION_H_INCLUDED

#define SIZE 50
typedef struct{
    char Name[15];
    char Height[15];
    char Weight[15];
} Info;
void Find_Revise(Info* , int , char , int* );

#endif // FUNCTION_H_INCLUDED

main.c

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

int main()
{
    int num, i;
    char instr;
    int isEnd=0;
    Info List[SIZE];

    scanf("%d", &num);
    for(i=0;i<num;i++){
        scanf("%s%s%s", List[i].Name, List[i].Height, List[i].Weight);
    }

    while(!isEnd){
        scanf(" %c", &instr);
        Find_Revise(List, num, instr, &isEnd);
    }

    return 0;
}

Input

1. The first line N is the number of the students, N ≦ 50.

2. The following N lines are sets of data, where length of Name ≦ 8 characters(alphabet), Height is a 3-digits integer, and Weight is a 2-digit integer.

3. The remaining lines are instructions, where instruction 'F' is followed by a string (length ≦ 8), instruction 'R' is followed by a integer representing the ith raw data, Name, Height, and Weight.

Output

1. Each Name in the output takes 10 characters space, each Height and Weight take 8 characters space. (i.e. %-10s......)

2. Note that there is a newline ‘\n’ at the end of each line.

Sample Input  Download

Sample Output  Download

Partial Judge Code

11292.c

Partial Judge Header

11292.h

Tags




Discuss