当前位置:网站首页>[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);
}
}
}
边栏推荐
- [Yu Yue education] Liaoning Vocational College of Architecture Web server application development reference
- Code Review关注点
- Unity | 实现面部驱动的两种方式
- Leetcode1961. Check whether the string is an array prefix
- XSS learning XSS lab problem solution
- 【Flask】响应、session与Message Flashing
- 黄金价格走势k线图如何看?
- Une image! Pourquoi l'école t'a - t - elle appris à coder, mais pourquoi pas...
- A Cooperative Approach to Particle Swarm Optimization
- SPIR-V初窺
猜你喜欢

A picture to understand! Why did the school teach you coding but still not

Some features of ECMAScript

3D模型格式汇总

Superfluid_ HQ hacked analysis

Loop structure of program (for loop)

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

A Cooperative Approach to Particle Swarm Optimization

Daily practice - February 13, 2022
![[solved] how to generate a beautiful static document description page](/img/c1/6ad935c1906208d81facb16390448e.png)
[solved] how to generate a beautiful static document description page

Threedposetracker project resolution
随机推荐
leetcode刷题_反转字符串中的元音字母
VMware Tools安装报错:无法自动安装VSock驱动程序
Paddle框架:PaddleNLP概述【飞桨自然语言处理开发库】
ORA-00030
Condition and AQS principle
Redis' cache penetration, cache breakdown, cache avalanche
记一个 @nestjs/typeorm^8.1.4 版本不能获取.env选项问题
什么是弱引用?es6中有哪些弱引用数据类型?js中的弱引用是什么?
FFT 学习笔记(自认为详细)
Gartner released the prediction of eight major network security trends from 2022 to 2023. Zero trust is the starting point and regulations cover a wider range
Mlsys 2020 | fedprox: Federation optimization of heterogeneous networks
有谁知道 达梦数据库表的列的数据类型 精度怎么修改呀
Electrical data | IEEE118 (including wind and solar energy)
ctf. Show PHP feature (89~110)
Development trend of Ali Taobao fine sorting model
servlet(1)
JMeter BeanShell的基本用法 一下语法只能在beanshell中使用
[technology development -28]: overview of information and communication network, new technology forms, high-quality development of information and communication industry
Cglib dynamic agent -- example / principle
DOM introduction