上海交通大学05-07年计算机上机真题附答案

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

2005年上机试题

发信人: tiancai (tiancai), 信区: KaoyanExam

标题: Re: 问:今年cs上机题是什么?

发信站: 饮水思源(2005年04月01日16:10:39 星期五)

可能晚些时候会有人发出完整版本,我写一下我记到的东西:

1. 太恐怖了,

12翻一下是21对吗?

34翻一下是43对吗?

12+34是46对吗?46翻一下是64对吗?

现在给你21与43,把64输出就可以了。

2.

给你一串路径,譬如

a\b\c

a\d\e

b\cst

d

你把这些路径中蕴涵的目录结构给画出来,子目录直接列在父目录下面,并比父目录向右缩一格,就象这样

a

b

c

d

e

b

cst

d

同一级的需要按字母顺序排列,不能乱。

3. 这题听说.....有点问题。反正大概意思是这样的(除非我理解错了.....):有一个x[6][6] 任意的0<=i,j<=5 1<=x[i][j]<=10;

现在有一个起始位置i1,j1与一个结束位置i2,j2。

请找出一条从i1,j1到i2,j2的总代价最小的路径。

1. 只能沿上下左右四个方向移动

2. 总代价是每走一步的代价之和

3. 每步(从a,b到c,d)的代价是x[c][d]与其在a,b处状态的乘积

4. 初始状态(在i1,j1时的状态)是1,每走一步,状态按如下公式变化

(走这步的代价% 4)+1

也就是状态只有4种:1,2,3 or 4.

2006年上机试题:

Problem A.Fibonacci

Input: fib.in

Output: Standard Output

Time limit: 5 second

Memory limit: 64 megabytes

The Fibonacci Numbers{0,1,1,2,3,5,8,13,21,34,55...} are defined by the recurre nce:

F0=0 F1=1 Fn=Fn-1+Fn-2,n>=2

Write a program to calculate the Fibonacci Numbers.

Input

The input file contains a number n and you are expected to calculate Fn.(0<=n< =30)

Output

Print a number Fn on a separate line,which means the nth Fibonacci Number.

Example

fib.in Standard Output

1 1

2 1

3 2

4 3

5 5

6 8

Problem B.WERTYU

Input: wertyu.in

Output: Standard Output

Time limit: 5 second

Memory limit: 64 megabytes

A common typing error is to place the hands on the keyboard one row to the rig ht of the correct position.So "Q" is typed as "W" and "J" is typed as "K" and

so on.You are to decode a message typed in this manner.

` 1 2 3 4 5 6 7 8 9 0 - = BackSp

Tab Q W E R T Y U I O P [ ] \

A S D F G H J K L ; ' Enter

Z X C V B N M , . /

Control Alt Space Alt Control

Input

The input file consist of several lines of text.Each line may contain digits,s paces,upper case letters(except Q,A,Z),or punctuation shown above(except back- quote(') which is left to the key "1").Keys labelled with words [Tab,BackSp,Co ntrol,etc.] are not represented in the input.

Output

You are to replace each letter or punctuation symbol by the one immediately to

its left on the QWERTY keyboard shown above.Spaces in the input should be ech oed in the output.

Example

wertyu.in Standard Output

O S, GOMR YPFSU/ I AM FINE TODAY.

Problem C.String Matching

Input: matching.in

Output: Standard Output

Time limit: 5 second

Memory limit: 64 megabytes

Finding all occurrences of a pattern in a text is a problem that arises freque

ntly in text-editing programs.

Typically,the text is a document being edited,and the pattern searched for is

a particular word supplied by the user.

We assume that the text is an array T[1..n] of length n and that the pattern i

s an array P[1..m] of length m<=n.We further assume that the elements of P and

T are all alphabets(∑={a,b...,z}).The character arrays P and T are often cal

led strings of characters.

We say that pattern P occurs with shift s in the text T if 0<=s<=n and T[s+1..

s+m] = P[1..m](that is if T[s+j]=P[j],for 1<=j<=m).

If P occurs with shift s in T,then we call s a valid shift;otherwise,we call s

相关文档
最新文档