C/C++知识点之计算机复试上机试题(c语言版)
小标 2018-08-27 来源 : 阅读 1744 评论 0

摘要:本文主要向大家介绍了C/C++知识点之计算机复试上机试题(c语言版),通过具体的内容向大家展示,希望对大家学习C/C++知识点有所帮助。

本文主要向大家介绍了C/C++知识点之计算机复试上机试题(c语言版),通过具体的内容向大家展示,希望对大家学习C/C++知识点有所帮助。

Introduction

The project will read flight data from an input file andflight path requests from another input file and output the requiredinformation.

?

Your Task

Your program should determine if aparticular destination airport can be reached from a particular originatingairport within a particular number of hops.

A hop (leg of a flight) is a flight from one airport to anotheron the path between an originating and destination airports.

For example, the flight plan from PVG to PEK might be PVG→ CAN → PEK. So PVG → CAN would be a hop and CAN → PEK would be a hop.

?

Input Data Files

Path InputFile(PathInput.txt)

This input file will consist of a number of single origination/destinationairport pairs (direct flights). The first line of the file will contain aninteger representing the total number of pairs in the rest of the file.

6

[PVG, CAN]

[CAN, PEK]

[PVG, CTU]

[CTU, DLC]

[DLC, HAK]

[HAK, LXA]

?

PathRequest File(PathRequest.txt)

This input file will contain a sequence of pairs oforigination/destination airports and a max number of hops. The first line ofthe file will contain an integer representing the number of pairs in the file.

2

[PVG, DLC, 2]

[PVG, LXA, 2]

?

OutputFile(Output.txt)

For each pair in the Path Request File, your programshould output the pair followed by “YES” or “NO” indicating that it is possible to get from the origination to destinationairports within the max number of hops or it is not possible,respectively.

[PVG, DLC, YES]

[PVG, LXA, NO]

Assumptions youcan make:

You may make the following simplifying assumptions inyour project:

l? C/C++ is allowed to be used.

l? All airport codes will be 3 letters and will be in allcaps

l? Origination/destination pairs are unidirectional. Toindicate that both directions of flight are possible, two entries would appearin the file. For example, [PVG, PEK] and [PEK, PVG] would have to be present inthe file to indicate that one could fly from Shanghaito Beijing and from Beijingto Shanghai.

\

题意理解:

给定一个图,任意输入图中两点,输出这两个点是否能在给定最大跳数内连通

 

例如

[PVG, DLC, 2] 给定最大跳数是2,实际跳数是2 未超过最大跳数 输出YES
[PVG, LXA, 2]给定最大跳数是2,实际跳数是4 超过最大跳数 输出NO

由于不会从文件中直接读取

6
[PVG, CAN]
[CAN, PEK]
[PVG, CTU]
[CTU, DLC]
[DLC, HAK]
[HAK, LXA]
2
[PVG, DLC, 2]
[PVG, LXA, 2]
这样的数据
所以只能模拟文件读取后的输入状态即:
6
PVG CAN
CAN PEK
PVG CTU
CTU DLC
DLC HAK
HAK LXA
3
PVG DLC 2
PVG LXA 2

输出结果
[PVG, DLC, YES]
[PVG, LXA, NO]

这个题算法不难就是个DFS,就是图结点是字符,有点坑

下面给出程序,不一定对,程序使用方法

输入数据

6
PVG CAN
CAN PEK
PVG CTU
CTU DLC
DLC HAK
HAK LXA
3
PVG DLC 2

PVG LXA 2

输出数据

[PVG, DLC, YES]

[PVG, LXA, NO]

#include
#include 

struct nodeinfo
{
 char no[10];//结点的名称;
 char joint[100][10];//与该结点相连的所有结点的集合
 int num_edge=0;//结点的度数
 int visited;//访问标志位 
}node[500];

int num_node=0,flag;// num_node是图中结点的个数 

int ni(char a[])//找出字符结点在结构体数组中的位置 
{
 for(int i=0;i<num_node;i++) if(!strcmp(node[i].no,a))="" return="" i;="" -1;="" 点不存在置为-1="" }="" bool="" islink(char="" a[],char="" b[])="" 判断两结点是否连通="" {="" int="" i="ni(a);" for(int="" j="0;j          
                
            

本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注职坐标编程语言C/C+频道!

本文由 @小标 发布于职坐标。未经许可,禁止转载。
喜欢 | 0 不喜欢 | 0
看完这篇文章有何感觉?已经有0人表态,0%的人喜欢 快给朋友分享吧~
评论(0)
后参与评论

您输入的评论内容中包含违禁敏感词

我知道了

助您圆梦职场 匹配合适岗位
验证码手机号,获得海同独家IT培训资料
选择就业方向:
人工智能物联网
大数据开发/分析
人工智能Python
Java全栈开发
WEB前端+H5

请输入正确的手机号码

请输入正确的验证码

获取验证码

您今天的短信下发次数太多了,明天再试试吧!

提交

我们会在第一时间安排职业规划师联系您!

您也可以联系我们的职业规划师咨询:

小职老师的微信号:z_zhizuobiao
小职老师的微信号:z_zhizuobiao

版权所有 职坐标-一站式IT培训就业服务领导者 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
 沪公网安备 31011502005948号    

©2015 www.zhizuobiao.com All Rights Reserved

208小时内训课程