临汾市网站建设_网站建设公司_轮播图_seo优化
2026/1/11 20:16:06 网站建设 项目流程

2025年上海交通大学计算机考研复试机试真题

2025年上海交通大学计算机考研复试上机真题

历年上海交通大学计算机考研复试上机真题

历年上海交通大学计算机考研复试机试真题

更多学校完整题目开源地址:https://gitcode.com/u014339447/pgcode

百度一下pgcode即可查看,输入 “学校名称” 即可筛选该校历年机试真题,包括真题、ac代码、解题思路、视频讲解。

水杯倒水-上海交通大学

题目描述

给出三个杯子的容量A AAB BBC CC,其中刚开始时C CC杯是满的,A AAB BB是空的。

现在在保证不会有漏水的情况下进行如下操作:

将一个杯子x xx的水倒到另一个杯子y yy中,如果x xx空了或者y yy满了就停止(满足其中一个条件才停下)

现问C CC中水量有多少种可能性(A AAB BBC CC为非负整数)

输入格式

输入包含多组测试数据。

每组数据占一行,包含三个整数A AAB BBC CC

输出格式

每组数据输出一个结果,占一行。

输入样例
0 5 5 2 2 4
输出样例
2 3
#include<bits/stdc++.h>usingnamespacestd;structState{inta,b,c;};intmain(){ios::sync_with_stdio(false);cin.tie(nullptr);intA,B,C;while(cin>>A>>B>>C){boolvisited[A+1][B+1][C+1]={0};set<int>result;queue<State>q;q.push({0,0,C});visited[0][0][C]=true;intcap[3]={A,B,C};while(!q.empty()){auto[a,b,c]=q.front();q.pop();result.insert(c);intcur[3]={a,b,c};// 6 possible pours: i -> jfor(inti=0;i<3;i++){for(intj=0;j<3;j++){if(i==j)continue;intx=cur[i];inty=cur[j];intspace=cap[j]-y;if(x==0||space==0)continue;intpour=min(x,space);intnxt[3]={cur[0],cur[1],cur[2]};nxt[i]-=pour;nxt[j]+=pour;if(!visited[nxt[0]][nxt[1]][nxt[2]]){visited[nxt[0]][nxt[1]][nxt[2]]=true;q.push({nxt[0],nxt[1],nxt[2]});}}}}cout<<result.size()<<"\n";}return0;}

String to int-上海交通大学

题目描述

给定一个字符串,字符串前可能有很多空格,字符串由数字 数字数字和各种字符组成,要求找到第一个数字 数字数字

若没有找到或者其值大于i n t intint上限,都返回− 1 -11

输入格式

一行一个字符串。

输出格式

一个整数表示结果。

输入样例
2016 000687CS01
输出样例
2016
#include<iostream>#include<string>usingnamespacestd;#include<climits>intmain(){string str,judge="";intc,e;intlimit=INT_MAX;while(limit){judge=(char)((limit%10)+'0')+judge;limit/=10;}while(getline(cin,str)){c=0;while(str[c]<='0'||str[c]>'9')c++;e=c+1;while(str[e]>='0'&&str[e]<='9')e++;string ans=str.substr(c,e-c);if(ans.size()>judge.size())ans="-1";if(ans.size()==judge.size()&&ans>judge)ans="-1";cout<<ans<<endl;}return0;}

Zero-上海交通大学

题目描述

You are given a sequence of integer numbers. Zero-complexity transposition of the sequence is the reverse of this sequence. Your task is to write a program that prints zero-complexity transposition of the given sequence.

输入格式

For each case, the first line of the input file contains one integer $ n $ -length of the sequence ($ 0 < n \leq 10,000 $). The second line contains $ n $ integers numbers-$ a_1, a_2, \ldots, a_n $ ($ -1,000,000,000,000,000 \leq a_i \leq 1,000,000,000,000,000 $).

输出格式

For each case, on the first line of the output file print the sequence in the reverse order.

输入样例
5 -3 4 6 -8 9
输出样例
9 -8 6 4 -3
#include<iostream>#include<vector>usingnamespacestd;intmain(){intn;cin>>n;vector<longlong>sequence(n);for(inti=0;i<n;++i){cin>>sequence[i];}for(inti=n-1;i>=0;--i){cout<<sequence[i];if(i>0){cout<<" ";}}cout<<endl;return0;}

走棋盘-上海交通大学

题目描述

给定一个N × M N \times MN×M的方格棋盘,请问一个棋子从棋盘左上角出发,能否在不重复经过棋盘上的方格的情况下,遍历整个棋盘一次再回到起点。

输入格式

多组输入。

输入棋盘大小N × M N \times MN×M

N , M < = 10 N, M <= 10N,M<=10

输出格式

每组数据输出一行一个结果,如果能回到起点则输出Y,否则输出N

输入样例
1 2 2 2
输出样例
Y Y
whileTrue:try:line=input()ifnotline:break# 使用map函数将分割后的字符串转换为整数a,b=map(int,line.split())ifa==1orb==1:ifa>2orb>2:print("N")continueelse:print("Y")continueifa%2==1andb%2==1:print("N")else:print("Y")exceptValueError:print("请输入两个有效的整数,用空格分隔")exceptEOFError:break

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询