查詢學生資訊

2021-07-09 14:48:19 字數 1058 閱讀 5059

題目描述:輸入n個學生的資訊,然後進行查詢。

輸入:輸入的第一行為n,即學生的個數(n<=1000)

接下來的n行包括n個學生的資訊,資訊格式如下:

01 李江 男 21

02 劉唐 男 23

03 張軍 男 19

04 王娜 女 19

然後輸入乙個m(m<=10000),接下來會有m行,代表m次查詢,每行輸入乙個學號,格式如下:

0203

0104

輸出:輸出m行,每行包括乙個對應於查詢的學生的資訊。

如果沒有對應的學生資訊,則輸出「no answer!」

樣例輸入:

4

01 李江 男 21

02 劉唐 男 23

03 張軍 男 19

04 王娜 女 19502

0301

0403

樣例輸出:

02 劉唐 男 23

03 張軍 男 19

01 李江 男 21

04 王娜 女 19

03 張軍 男 19

#include "stdio.h"

#include "string.h"

#include using namespace std;

struct student //用於表示學生個體的結構體

}buf[1000];

int main()

else if(tmp>0)

top = mid+1;

else

base = mid+1;

}if(ans == -1)

else

printf("%s %s %s %d\n",buf[ans].no,buf[ans].name,buf[ans].***,buf[ans].age);

} }return 0;

}

本題是利用二分查詢

查詢學生資訊

二分查詢 題目描述 輸入n個學生的資訊,然後進行查詢。輸入 輸入的第一行為n,即學生的個數 n 1000 接下來的n行包括n個學生的資訊,資訊格式如下 01 李江 男 21 02 劉唐 男 23 03 張軍 男 19 04 王娜 女 19 然後輸入乙個m m 10000 接下來會有m行,代表m次查詢...

查詢學生資訊

include include include include include include include include include includeusing namespace std typedef long long ll const int n 1e5 10,mod 1e6 con...

查詢學生資訊

輸入n個學生的資訊,然後進行查詢。輸入的第一行為n,即學生的個數 n 1000 接下來的n行包括n個學生的資訊,資訊格式如下 01 李江 男 21 02 劉唐 男 23 03 張軍 男 19 04 王娜 女 19 然後輸入乙個m m 10000 接下來會有m行,代表m次查詢,每行輸入乙個學號,格式如...