历年上海交通大学计算机保研上机真题

2025上海交通大学计算机保研上机真题

2024上海交通大学计算机保研上机真题

2023上海交通大学计算机保研上机真题
在线测评链接:https://pgcode.cn/school

String Match

题目描述

Finding all occurrences of a pattern in a text is a problem that arises frequently 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 T1...n of length n and that the pattern is an array P1...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 called strings of characters.

We say that pattern P occurs with shift s in the text T if 0 <= s <= n and Ts+1...s+m = P1...m (that is, if Ts+j = Pj, for 1 <= j <= m). If P occurs with shift s in T, then we call s a valid shift; otherwise, we call s an invalid shift. Your task is to calculate the number of valid shifts for the given text T and pattern P.

输入格式

For each case, there are two strings T and P on a line, separated by a single space. You may assume both the length of T and P will not exceed 10^6.

输出格式

You should output a number on a separate line, which indicates the number of valid shifts for the given text T and pattern P.

输入样例
复制代码
abababab abab
输出样例
复制代码
3

二次方程计算器

题目描述

设计一个二次方程计算器,用于求解给定的二次方程。

输入格式

每个输入是关于 x 的一个二次方程表达式,为了简单,每个系数都是整数形式。

输出格式

每个案例输出两个实数(由小到大输出,中间由空格隔开),保留两位小数;如果无解,则输出"No Solution"。

输入样例
复制代码
x^2+x=3x+4
输出样例
复制代码
-1.24 3.24

WERTYU

题目描述

A common typing error is to place the hands on the keyboard one row to the right 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.

输入格式

Input consists of several lines of text. Each line may contain digits, spaces, upper case letters (except Q, A, Z), or punctuation shown above except back-quote (\`). Keys labelled with words Tab, BackSp, Control, etc. are not represented in the input.

输出格式

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 echoed in the output.

输入样例
复制代码
O S, GOMR YPFSU/
输出样例
复制代码
I AM FINE TODAY.

Simple Sorting

题目描述

You are given an unsorted array of integer numbers. Your task is to sort this array and remove possible duplicated elements occurring in it.

输入格式

For each case, the first line of the input contains an integer number N representing the quantity of numbers in this array (1 ≤ N ≤ 1000). Next N lines contain N integer numbers (one number per each line) of the original array.

输出格式

For each case, output file should contain at most N numbers sorted in ascending order. Every number in the output file should occur only once.

输入样例
复制代码
6
8
8
7
3
7
7
输出样例
复制代码
3 7 8

Old Bill

题目描述

Among grandfather's papers a bill was found:

"72 turkeys $679 "

The first and last digits of the number representing the total price are faded (denoted by _). What are the two faded digits and what was the price per turkey?

We want to write a program that solves a general version of this problem:

"N turkeys $XYZ"

  • N (number of turkeys) is between 1 and 99 (inclusive)
  • The total price originally had 5 digits, but only the middle 3 digits (X, Y, Z) are visible
  • The first digit is nonzero
  • Each turkey costs the same integer price
    Given N, X, Y, Z, find the two faded digits and the original total price. If multiple solutions exist, choose the most expensive one (maximum price per turkey).
输入格式

The first line contains integer N (0 < N < 100). The second line contains three digits X, Y, Z separated by spaces (representing the middle three digits of the total price).

输出格式

Output the two faded digits (first and last) followed by the maximum price per turkey (integer).

输入样例
复制代码
72
6 7 9
输出样例
复制代码
3 5 11

Fibonacci

题目描述

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

F₀ = 0, F₁ = 1, Fₙ = Fₙ₋₁ + Fₙ₋₂ (n ≥ 2).

Write a program to calculate the Fibonacci Numbers.

输入格式

Each case contains a number n, and you are expected to calculate Fₙ (0 ≤ n ≤ 30).

输出格式

For each case, print a number Fₙ on a separate line, which means the nth Fibonacci Number.

输入样例
复制代码
1
输出样例
复制代码
1

数字反转

题目描述

12 翻一下是 21,34 翻一下是 43,12+34 是 46,46 翻一下是 64。

现在有两个任意正整数,问这两个数反转的和是否等于两个数的和的反转。

输入格式

每行两个正整数 a 和 b(0 < a, b <= 10000)。

输出格式

如果满足题目的要求输出 a+b 的值,否则输出 NO。

输入样例
复制代码
12 34
99 1
输出样例
复制代码
46
NO

涂颜色

题目描述

在这个游戏中,有一个 n 行 m 列的方阵。

现在要为这个方阵涂上黑白两种颜色。

规定左右相邻两格的颜色不能相同。

请你统计有多少种涂色的方法。

由于答案很大,你需要将答案对 1000000007 取模。

1≤n,m≤10^100000

输入格式

输入两个数 n,m

输出格式

输出总共的方案数

输入样例
复制代码
2 2
输出样例
复制代码
4

最长平衡子串

题目描述

我们定义满足最多由两种字符组成,并且字符串中两个字符的数量之差的绝对值小于等于 k 的字符串为 k 阶平衡字符串。

例如 abb 就是 1 阶平衡字符串,也是 2 阶平衡字符串。

现在给出一个长度为 n 并且最多由两种字母字符组成的字符串 s。

对于每次询问 qi,求 s 字符串的所有子串中最长的 qi 阶平衡字符串的长度。

输入格式

多组测试数据,对于每组测试数据包含 m+2 行:

  • 第 1 行包含两个整数 n,m(最大 10^5)
  • 第 2 行是一个长度为 n 的字符串 s
  • 接下来 m 行,每行一个整数 qi 表示询问
输出格式

对于每组测试数据的每次询问,输出一个整数表示原字符串的子串中最长的 qi 阶平衡字符串的长度。

输入样例
复制代码
5 2
baaaa
2
1
输出样例
复制代码
4
3

最小面积子矩阵

题目描述

一个 N*M 的矩阵,找出这个矩阵中所有元素的和不小于 K 的面积最小的子矩阵(矩阵中元素个数为矩阵面积)。

输入格式

每个案例第一行三个正整数 N,M<=100,表示矩阵大小,和一个整数 K。

接下来 N 行,每行 M 个数,表示矩阵每个元素的值。

输出格式

输出最小面积的值。

如果任意矩阵的和都小于 K,直接输出-1。

输入样例
复制代码
4 4 10
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
输出样例
复制代码
1
相关推荐
humors2211 天前
【转】逻辑基础知识
学习·考研·读书·教育·逻辑·升学·语文
IT研究室2 天前
最新大数据毕业设计选题推荐-基于大数据的考研相关视频数据可视化分析-大数据-Spark-Hadoop-Bigdata
大数据·考研·课程设计
DevNo2 天前
我的2026中医执业医师笔试资料使用小记
笔记·学习·考研
DevNo2 天前
我的医学考研学习品牌接触记录
学习·考研
知了学历孙老师2 天前
非全硕士上课怎么安排:周末班、集中班还是网络班
人工智能·考研·福建成考
小淮AI3 天前
医学考研视频课程选择思路:西综、英语、政治分阶段梳理
考研
唐维康3 天前
昆明理工大学817通信工程考研名额一年比一年少
人工智能·考研·昆明理工大学·昆明理工大学通信考研
晚来的棠棠3 天前
27考研数学超全资料PDF
考研·pdf
新中地GIS开发老师5 天前
保研上岸后,地理学三年怎么走?
考研·地信
HKUST_6 天前
香港科技大学工学院2027FALL研究生项目招生宣讲会-长安大学专场
考研·香港科技大学·工学院·香港留学