博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
华为13年机试题
阅读量:7080 次
发布时间:2019-06-28

本文共 7440 字,大约阅读时间需要 24 分钟。

hot3.png

及格成绩 描述:10个学生考完期末考试评卷完成后,A老师需要划及格线,要求如下: (1)及格线是10的倍数;(2)保证至少有60%的学生及格;(3)如果所有的学生都高于60分,则及格线为60分; 运行时间限制:无限制 内存限制: 无限制 输入: 输入10个整数,取值0-100 输出: 输出及格线,10的倍数 样例输入: 61 51 49 30 20 10 70 80 90 99 样例输出: 50

亮着电灯的盏数 一条长廊里一次装有n(1<= n<=65536)盏电灯,从头到尾编号1、2、3、...n-1、n。每盏电灯由一个拉线开关控制。开始,电灯全部关着。有n个学生从长廊穿过。第一个学生把号码凡是1的倍数的电灯的开关拉一下,接着第二个学生把号码凡是2的倍数的电灯的开关拉一下,接着第三个学生把号码凡是3的倍数的电灯的开关拉一下,如此继续下去,最后第n个学生把号码凡是n的倍数的电灯的开关拉一下。n个学生按此规定走完后,长廊里电灯有几盏亮着。注:电灯数和学生一致。 运行时间限制:无限制 内存限制: 无限制 输入: 电灯的数量 输出: 亮着的电灯数量 样例输入: 3 样例输出: 1

地铁换乘 已知2条地铁线路,其中A为环线,B为东西向线路,线路都是双向的。经过的站点名分别如下,两条线交叉的换乘点用T1、T2表示。编写程序,任意输入两个站点名称,输出乘坐地铁最少需要经过的车站数量(含输入的起点和终点,换乘站点只计算一次) 地铁线A(环线)经过车站:A1 A2 A3 A4 A5 A6 A7 A8 A9 T1 A10 A11 A12 A13 T2 A14 A15 A16 A17 A18 地铁线B(直线)经过车站:B1 B2 B3 B4 B5 T1 B6 B7 B8 B9 B10 T2 B11 B12 B13 B14 B15 运行时间限制: 无限制 内存限制: 无限制 输入: 输入两个不同的站名 输出: 输入最少经过的站数,含输入的起点和终点,换乘站点只计算一次 样例输入: A1 A3 样例输出: 3 第一题: <!-- lang: cpp --> #include <stdio.h> #include <stdlib.h> int main() { int score[10]; int pass_score = 0; int tmp = 0; int i = 0,j = 0; int flag = 1; printf("please input the students' score(10)\n"); for(;i< 10; i++) { scanf("%d",&score[i]); if(score[i] < 60) flag = 0; } for(i = 0;i < 10;i++) { for(j = 0;j < 10 - i - 1;j++) { if(score[i] > score[i + j + 1]) { tmp = score[i + j + 1]; score[i + j + 1] = score[i]; score[i] = tmp; } } } printf("the score (desc):\n"); for(i = 0;i < 10;i++) { if(i == 5) printf("\n"); printf("%d\t",score[i]); } printf("\n"); if(flag == 0) pass_score = score[4]/10*10; else pass_score = 60; printf("the pass_score = %d\n",pass_score); return 0; } 第二题: #include <stdio.h> #include <stdlib.h> #include <math.h> int issqrt(int n); int main(){ int light_num = 0; int sum = 0; int i = 0; printf("please input the number of the lights: "); scanf("%d",&light_num); for(i = 1; i < light_num + 1; i++) if(issqrt(i)) sum++; printf("the number of the lights who are on at last is %d\n",sum); return 0; }

int issqrt(int n){    int i = 0;    for(i = 1; i < n + 1; i++)	    if(i * i == n)		    return 1;    return 0;}

第三题: #include <stdio.h> #include <stdlib.h> #include <string.h>

#define CIR_NUM 20#define LIN_NUM 17typedef struct station{        char name[5];           //the name of the station        struct station *next;    //the pointer that points to the next node        struct station *pre;     //the pointer that points to the pre node        int flag;               //the type of the subway        int number;}station;void create_circle_list(station **clist_head);void create_line_list(station **llist_head);station *search_station_c(char name[5],station **clist_head);station *search_station_l(char name[5],station **llist_head);int ways_1(int num_1,int num_2);int ways_2(int num_1,int num_2);int main(){    station *clist_hd;      //the pointer that point to the first node on the station subway    station *llist_hd;          //the pointer that point to the first node on the station subway    station *phead,*ptail;    char query_name_first[5];    char query_name_second[5];    int yes_or_no = 1;    int a,b,c,d;    int result;    phead = ptail = NULL;    //create the circle_list;    printf("now create the cirlce_list!\n");    create_circle_list(&clist_hd);    printf("circle_list is created successfully!\n");    printf("now create the line_list!\n");    create_line_list(&llist_hd);    printf("line_list is created successfully!\n");    while(yes_or_no == 1){        printf("please input the names of the stations which you want to query!\n");        scanf("%s%s",query_name_first,query_name_second);        phead = (station *)malloc(sizeof(station));        ptail = (station *)malloc(sizeof(station));        if(search_station_c(query_name_first,&clist_hd) != NULL)                phead = search_station_c(query_name_first,&clist_hd);        if(search_station_l(query_name_first,&llist_hd) != NULL)            phead = search_station_l(query_name_first,&llist_hd);        if(search_station_c(query_name_second,&clist_hd))            ptail = search_station_c(query_name_second,&clist_hd);        if(search_station_l(query_name_second,&llist_hd))            ptail = search_station_l(query_name_second,&llist_hd);        if(phead->flag == 1 && ptail->flag == 1){            result = ways_1(phead->number,ptail->number);        }        else if(phead->flag == 0 && ptail->flag == 0){            result = ways_2(phead->number,ptail->number);        }        else if(phead->flag ==1 && ptail->flag == 0){            a = ways_1(phead->number,10);            b = ways_1(phead->number,15);            c = ways_2(ptail->number,6);            d = ways_2(ptail->number,12);            result = (a + c) > (b + d)? b + d : a + c;            result--;        }        else{            a = ways_2(phead->number,10);            b = ways_2(phead->number,15);            c = ways_1(ptail->number,6);            d = ways_1(ptail->number,12);            result = (a + c) > (b + d)? b + d : a + c;            result--;        }        printf("the number of the least stations between %s and %s is %d\n\n",\            phead->name,ptail->name,result);        printf("do you want to continue('1' for yes,'0' for no)!\n");        scanf("%d",&yes_or_no);        }    return 0;}void create_circle_list(station **clist_head){    station *tail = NULL;    station *head = NULL;    int count = 0;    printf("please input the name of the station!(%d)\n",CIR_NUM);    head = (station *)malloc(sizeof(station));    scanf("%s",head->name);    head->flag = 1;    count++;    head->number = count;    tail = head;    while(count < CIR_NUM){        tail->next = (station *)malloc(sizeof(station));        tail->next->pre = tail;        tail = tail->next;        scanf("%s",tail->name);        tail->flag = 1;        count++;        tail->number = count;    }    tail->next = head;    head->pre = tail;    *clist_head = head;}void create_line_list(station **llist_head){    station *head = NULL;    station *tail = NULL;    int count = 0;    printf("please input the name of the station!(%d)\n",LIN_NUM);    head = (station *)malloc(sizeof(station));    scanf("%s",head->name);    head->flag = 0;    count++;    head->number = count;    tail = head;    while(count < LIN_NUM){        tail->next = (station *)malloc(sizeof(station));        tail->next->pre = tail;        tail = tail->next;        scanf("%s",tail->name);        tail->flag = 0;        count++;        tail->number = count;    }    tail->next = NULL;    *llist_head = head;}station *search_station_c(char name[5],station **clist_head){    station *ptemp;    ptemp = NULL;    ptemp = *clist_head;    int count = 0;    while(count < CIR_NUM){        if(strcmp(ptemp->name,name) == 0){            return ptemp;        }        ptemp = ptemp->next;        count++;    }    return NULL;}station *search_station_l(char name[5],station **llist_head){    station *ptemp;    ptemp = NULL;    ptemp = *llist_head;    int count = 0;    while(count < LIN_NUM){        if(strcmp(ptemp->name,name) == 0){            return ptemp;        }        ptemp = ptemp->next;        count++;    }    return NULL;}int ways_1(int num_1,int num_2){    int result;    result = num_1 - num_2;    if(result < 0)        result = -result;    result += 1;    if(result > CIR_NUM / 2 + 1)        result = CIR_NUM - result + 2;    return result;}int ways_2(int num_1,int num_2){    int result;   result = num_1- num_2;    if(result < 0)        result =  -result;    result += 1;    return result;}

转载于:https://my.oschina.net/u/1392563/blog/206549

你可能感兴趣的文章
MahApps.Metro
查看>>
IOS UIWebView的一些用法总结
查看>>
字符串及其他类型数据的比较
查看>>
面向对象二次整理(基础,属性引用,方法引用.绑定方法)
查看>>
Quick-cocos2d-x3.3 Study (十)--------- 添加动画
查看>>
网络学习目录
查看>>
《结对-贪吃蛇游戏-需求分析》
查看>>
入门01
查看>>
Guava包学习--Hash
查看>>
PAT-乙级-01
查看>>
CImage
查看>>
面向对象01
查看>>
[C++参考]私有成员变量的理解
查看>>
五.获得MYSQL数据库自动生成的主键
查看>>
小米4安装apk时出现INSTALL_FAILED_NO_MATCHING_ABIS
查看>>
窗体之间传递值的几种方法
查看>>
springboot开启定时任务 添加定时任务 推送
查看>>
html+css高度100%的时候边框超出,出现滚动条的解决办法,带边框的100%高度
查看>>
最大子段和(洛谷P1115,动态规划递推)
查看>>
nyoj 311 完全背包
查看>>