-
Title Description:
-
Enter the information for the N students and then make a query.
-
Input:
-
Enter the first behavior N, which is the number of students (n<=1000)
The next n rows include information about n students, formatted as follows: 01 Li Jiang Male 2102 Liu Tangnan 2303 Zhang June 1904 Wang na female 19 then enter a M (m<=10000), then there will be M-line, the M-query, each line entered a school number, the format is as follows: 02030104
-
Output:
-
Output m lines, each of which includes a message for the student that corresponds to the query.
Output "No answer!" if no student information is applicable
-
Sample input:
-
401 Li Jiang Male 2102 Liu Tangnan 2303 Zhang June male 1904 Wang na female 1950203010403
-
-
Sample output:
-
02 Liu Tangnan 2303 Zhang June men 1901 Li Jiang men 2104 Wang na female 1903 Zhang June men 19
1#include <stdio.h>2#include <algorithm>3#include <string.h>4#include <fstream>5 using namespacestd;6 structstu{7 Charstu_no[ -];8 Charstu_name[ -];9 Charstu_sex[ -];Ten Charstu_age[ -]; One BOOL operator< (ConstStu & X)Const{ A returnstrcmp (Stu_no,x.stu_no) <0; - } -}buf[ +]; the intMain () { - intN; - while(SCANF ("%d", &n)! =EOF) { - for(intI=0; i<n;i++){ +scanf"%s%s%s%s", - buf[i].stu_no,buf[i].stu_name,buf[i].stu_sex,buf[i].stu_age); + } ASort (buf,buf+n); at intT; -scanf"%d",&t); - while(t!=0) {t--; - intans=-1; - Chartemp_no[ -]; -scanf"%s", temp_no); in inttop=n-1,Base=0; - while(top>=Base){ to intMid= (top+Base)/2; + inttmp=strcmp (buf[mid].stu_no,temp_no); - if(tmp==0){ theans=mid; * Break; $ }Panax Notoginseng Else if(tmp>0) top=mid-1; - Else Base=mid+1; the } + if(ans==-1) Aprintf"No answer!\n"); the Elseprintf"%s %s%s%s\n", + buf[ans].stu_no,buf[ans].stu_name,buf[ans].stu_sex,buf[ans].stu_age); - } $ } $}
The beginning of the array is small, always WA, later to do the problem array to open, memory ultra-small
Nine degrees OJ topic 1069: Find student information