当前位置:网站首页>[Jiudu OJ 09] two points to find student information
[Jiudu OJ 09] two points to find student information
2022-07-06 01:27:00 【CodeLinghu】
【 Nine degrees OJ 09】 Two points to find student information
List of articles
One 、 The question

Two 、 The answer process
Ideas :
Two points search
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct student// Used to represent the structure of students
{
char sno[100];// Student number
char name[100];// full name
char sex[10];// Gender
int age;// Age
// The comparison function embedded in the structure
bool operator < (const student &b) const// Comparison function , Make it possible to sort Function order
{
return strcmp(sno,b.sno)<0;
}
}buf[1000];
int main()
{
int n,m;
char x[100];
while(scanf("%d",&n)!=EOF)
{
for(int i=0;i<n;i++)
{
scanf("%s %s %s %d",&buf[i].sno,&buf[i].name,&buf[i].sex,&buf[i].age);
}
sort(buf,buf+n);// Sort the array , Make it sort in ascending order by student number
scanf("%d",&m);
while(m--!=0)
{
int ans=-1;
scanf("%s",&x);// Enter the student number to be searched
int top=n-1,base=0;// The starting subscript is 0, The ending subscript is n-1, Find the entire array
int cnt=1;
while(top>=base)
{
int mid=(top+base)/2;// Calculate the middle point subscript
int tmp=strcmp(buf[mid].sno,x);// Compare the intermediate student number with the target student number
if(tmp==0)
{
ans=mid;
break;// If equal, then complete the jump out of the binary search
}
else if(tmp<0)base=mid+1;// If less than , Then the starting subscript becomes the coordinate of the point after the intermediate node
else top=mid-1;// If more than , Then the end subscript becomes the subscript before the intermediate node
printf("%d\t",mid);
printf("%d\t",cnt++);
}
if(ans==-1)printf(" not find");// To find the failure
else printf("%s %s %s %d\n",buf[ans].sno,buf[ans].name,buf[ans].sex,buf[ans].age);
}
}
}
边栏推荐
- About error 2003 (HY000): can't connect to MySQL server on 'localhost' (10061)
- c#网页打开winform exe
- Poj2315 football games
- 3D vision - 4 Getting started with gesture recognition - using mediapipe includes single frame and real time video
- Unity | two ways to realize facial drive
- Mathematical modeling learning from scratch (2): Tools
- Spir - V premier aperçu
- Leetcode skimming questions_ Sum of squares
- IP storage and query in MySQL
- Unity VR solves the problem that the handle ray keeps flashing after touching the button of the UI
猜你喜欢

3D model format summary

C web page open WinForm exe

Threedposetracker project resolution

Xunrui CMS plug-in automatically collects fake original free plug-ins

Condition and AQS principle

500 lines of code to understand the principle of mecached cache client driver

How to extract MP3 audio from MP4 video files?

【SSRF-01】服务器端请求伪造漏洞原理及利用实例

VMware Tools installation error: unable to automatically install vsock driver

普通人下场全球贸易,新一轮结构性机会浮出水面
随机推荐
A Cooperative Approach to Particle Swarm Optimization
Une image! Pourquoi l'école t'a - t - elle appris à coder, mais pourquoi pas...
朝招金安全吗 会不会亏损本金
【全网最全】 |MySQL EXPLAIN 完全解读
Is chaozhaojin safe? Will it lose its principal
Paging of a scratch (page turning processing)
ClickOnce does not support request execution level 'requireAdministrator'
ORA-00030
3D vision - 4 Getting started with gesture recognition - using mediapipe includes single frame and real time video
Redis' cache penetration, cache breakdown, cache avalanche
有谁知道 达梦数据库表的列的数据类型 精度怎么修改呀
Luo Gu P1170 Bugs Bunny and Hunter
[detailed] several ways to quickly realize object mapping
ORA-00030
VMware Tools installation error: unable to automatically install vsock driver
Modify the ssh server access port number
2022 Guangxi Autonomous Region secondary vocational group "Cyberspace Security" competition and its analysis (super detailed)
Alibaba-Canal使用详解(排坑版)_MySQL与ES数据同步
Condition and AQS principle
Vulhub vulnerability recurrence 75_ XStream