当前位置:网站首页>[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);
}
}
}
边栏推荐
- Daily practice - February 13, 2022
- [机缘参悟-39]:鬼谷子-第五飞箝篇 - 警示之二:赞美的六种类型,谨防享受赞美快感如同鱼儿享受诱饵。
- Mlsys 2020 | fedprox: Federation optimization of heterogeneous networks
- Unity | 实现面部驱动的两种方式
- Dedecms plug-in free SEO plug-in summary
- yii中console方法调用,yii console定时任务
- Leetcode study - day 35
- Electrical data | IEEE118 (including wind and solar energy)
- 一图看懂!为什么学校教了你Coding但还是不会的原因...
- Leetcode1961. 检查字符串是否为数组前缀
猜你喜欢

MUX VLAN configuration

普通人下场全球贸易,新一轮结构性机会浮出水面

Pbootcms plug-in automatically collects fake original free plug-ins

IP storage and query in MySQL

【Flask】官方教程(Tutorial)-part3:blog蓝图、项目可安装化

3D模型格式汇总

Huawei Hrbrid interface and VLAN division based on IP

Leetcode skimming questions_ Invert vowels in a string

ThreeDPoseTracker项目解析

Threedposetracker project resolution
随机推荐
How to get all sequences in Oracle database- How can I get all sequences in an Oracle database?
Pbootcms plug-in automatically collects fake original free plug-ins
FFT 学习笔记(自认为详细)
[机缘参悟-39]:鬼谷子-第五飞箝篇 - 警示之二:赞美的六种类型,谨防享受赞美快感如同鱼儿享受诱饵。
Dede collection plug-in free collection release push plug-in
SCM Chinese data distribution
Leetcode 剑指 Offer 59 - II. 队列的最大值
Yii console method call, Yii console scheduled task
[Yu Yue education] Liaoning Vocational College of Architecture Web server application development reference
现货白银的一般操作方法
Leetcode sword finger offer 59 - ii Maximum value of queue
Idea sets the default line break for global newly created files
Ordinary people end up in Global trade, and a new round of structural opportunities emerge
IP storage and query in MySQL
How to get the PHP version- How to get the PHP Version?
Paddle框架:PaddleNLP概述【飞桨自然语言处理开发库】
Is chaozhaojin safe? Will it lose its principal
网易智企逆势进场,游戏工业化有了新可能
ClickOnce 不支持请求执行级别“requireAdministrator”
Unity VR solves the problem that the handle ray keeps flashing after touching the button of the UI