上海交通大学2005-2007年计算机上机真题附答案(2)
本站小编 半岛在线注册/2016-08-04
Problem D.Exponential Form
Input: form.in
Output: Standard Output
Time limit: 5 second
Memory limit: 64 megabytes
Every positive number can be presented by the exponential form.For example,
137 = 2^7 + 2^3 + 2^0
Let's present a^b by the form a(b).Then 137 is presented by 2(7)+2(3)+2(0).
Since 7 = 2^2 + 2 + 2^0 and 3 = 2 + 2^0 , 137 is finally presented by 2(2(2)+2
+2(0))+2(2+2(0))+2(0).
Given a positive number n,your task is to present n with the exponential form
which only contains the digits 0 and 2.
Input
The input file contains a positive integer n (n<=20000).
Output
You should output the exponential form of n an a single line.Note that,there s
hould not be any additional white spaces in the line.
Example
form.in
137
Stardard Output
2(2(2)+2+2(0))+2(2+2(0))+2(0)
form.in
1315
Stardard Output
2(2(2+2(0))+2)+2(2(2+2(0)))+2(2(2)+2(0))+2+2(0)
2006 年上机试题参考答案:
//A.cpp
//18 lines
#include "iostream"
#include "fstream"
using namespace std;
int fib(int n)
{
6
if (n==0) return 0;
else if (n==1) return 1;
else return fib(n-1)+fib(n-2);
}
void main()
{
fstream f("fib.in");
int n;
f>>n;
cout<<fib(n)<<endl;
}
//B.cpp
//28 lines
#include "iostream"
#include "fstream"
#include "string"
#include "stdio.h"
using namespace std;
char table[100]="`1234567890-=QWERTYUIOP[]\\ASDFGHJKL;'ZXCVBNM,./";
void main()
{
fstream f("wertyu.in");
char c[1000];
string s;
int tablelen = strlen(table);
while (!f.getline(c,1000).eof())
{
s = c;
int n = s.length();
for (int i=0;i<n;i++)
{
for (int j=0;j<tablelen;j++)
{
if (s[i]==table[j]) s[i]=table[j-1];
}
}
cout<<s<<endl;
}
}
//C.cpp
//24 lines
#include "iostream"
#include "fstream"
#include "string"
using namespace std;
int match(string s,string t)
{
int count=0;
string::size_type index = -1;
while ((index = s.find(t,index+1))!=string::npos) count++;
return count;
}
void main()
{
fstream f("matching.in");
string s,t;
while (!f.eof())
{
f>>s;
f>>t;
cout<<match(s,t)<<endl;
}
}
//D.cpp
//60 lines
#include "iostream"
#include "fstream"
#include "string"
using namespace std;
int getminex(int n)
{
int k=0;
int l=1;
while (1)
{
if (n<l) break;
else
{
l=l*2;
k++;
}
}
return k-1;
}
int getremain(int n)
{
int t=getminex(n);
int s=1;
for (int i=0;i<t;i++)
{
s=s*2;
}
return n-s;
}
string getform(int n)
{
if (n==0) return "";
else if (n==1) return "2(0)";
else if (n==2) return "2";
else if (n==4) return "2(2)";
else
{
string t,s;
int e = getminex(n);
if (e == 1) t= "";
else t = "("+getform(e)+")";
s = "2"+t;
int r = getremain(n);
if (r != 0) s = s+"+"+getform(r);
return s;
}
}
void main()
{
fstream f("form.in");
int n;
f>>n;
cout<<getform(n)<<endl;
}
参考试题1:
Fire Net
Suppose that we have a square city with straight streets. A map of a city is
a square board with n rows and n columns, each representing a street or a
piece of wall.
A blockhouse is a small castle that has four openings through which to
shoot. The four openings are facing North, East, South, and West,
相关话题/计算机
2008年上海交通大学计算机半岛在线注册复试上机试题
专业课半岛在线注册资料 本站小编 半岛在线注册 2016-08-042016年东北大学计算机专业基础半岛在线注册真题(完整版)
2016年东北大学计算机专业基础半岛在线注册真 题(完整版)凯程首发 一、简答 1、 循环语句while和dowhile的区别。 2、 有static声明的局部变量和自由变量的区别。 3、 根据 4、Int (*p)[4]和int *p[4]的区别 二、写出程序运行的结果 有一个是用指针作函数参数,实现数据的交换 有一个是a[9]={1, ...专业课半岛在线注册资料 本站小编 半岛在线注册 2016-07-312009-2015年计算机组成原理半岛在线注册大题
43.(8 分)某计算机的 CPU 主频为 500MHz,CPI 为 5(即执行每条指令平均需 5 个时钟周期)。假定某外设的数据传输率为 0.5MB/s,采用中断方式与主机进行数据传送,以 32 位为传输单位,对应的中断服务程序包含 18 条指令,中断服务的其他开销相当于 2 条指 令的执行时间。请回答下列问题,要求给出计算过程。 (1) ...专业课半岛在线注册资料 本站小编 半岛在线注册 2016-07-312009-2015年计算机组成原理半岛在线注册选择题
11.冯诺依曼计算机中指令和数据均以二进制形式存放在存储器中,CPU 区分它们的依据是 。 A.指令操作码的译码结果 B.指令和数据的寻址方式 C.指令周期的不同阶段 D.指令和数据所在的存储单元 11.C。考查指令的执行过程。 通常完成一条指令可分为取指阶段和执行 ...专业课半岛在线注册资料 本站小编 半岛在线注册 2016-07-31计算机科学与技术半岛在线注册报考注意事项
计算机科学与技术半岛在线注册报考注意事项 近几年由于专业的热门和半岛在线注册竞争的异常激烈,因此国内一些重点院校的计算机专业硕士生入学分数都非常高,这种情况在一些重点院校特别突出。报考计算机专业研究生的朋友一定要充分地认清这种现实情况,做好充分的准备,思想上要树立考试胜利的信心,并且做好刻苦复习 ...半岛在线注册报考信息 本站小编 半岛在线注册 2016-07-27计算机科学与技术专业解析
计算机科学与技术专业解析 一、培养目标 本专业培养和造就适应现代化建设需要。德智体全面发展、基础扎实、知识面宽、能力强、素质高具有创新精神,系统掌握计算机硬件、软件的基本理论与应用基本技能,具有较强的实践能力,能在企事业单位、政府机关、行政管理部门从事计算机技术研究和应用 ...半岛在线注册报考信息 本站小编 半岛在线注册 2016-07-27计算机软件与理论就业方向与就业前景
计算机软件与理论就业方向与就业前景 计算机科学与技术专业介绍 计算机科学与技术是研究计算机的设计与制造,以及信息获取、表示、存储、处理、传输和利用等方面的理论、原则、方法和技术的学科。它包括科学与工程技术两方面,两者互为作用,高度融合,这是计算机科学与技术学科的突出特点。计 ...半岛在线注册报考信息 本站小编 半岛在线注册 2016-07-27计算机应用技术就业方向与就业前景
计算机应用技术就业方向与就业前景 计算机应用技术专业介绍 计算机应用技术是计算机科学与技术专业下设的一个二级学科,某些院校可以授予理学学位,在此针对工学学位进行解析。本学科主要研究计算机各种应用中具有共性的理论、技术和方法,以及各种前沿性、创新性的计算机应用。 计算 ...半岛在线注册报考信息 本站小编 半岛在线注册 2016-07-27计算机系统结构就业方向与就业前景
计算机系统结构就业方向与就业前景 计算机系统结构专业介绍 计算机系统结构是计算机科学与技术专业下设的二级学科。某些院校可以授予理学学位,在此针对工学学位进行解析。计算机系统结构是计算机的的机器语言程序员或编译程序编写者所看到的外特性。所谓外特性,就是计算机的概念性结构和功能 ...半岛在线注册报考信息 本站小编 半岛在线注册 2016-07-27北京邮电大学计算机学院简介
北京邮电大学计算机学院简介 北京邮电大学计算机学院源于1985年9月成立的北京邮电大学计算机工程系,后经多次机构调整和更名,2008年9月由计算机科学与技术专业、网络工程专业、智能科学与技术专业和信息安全专业合并形成了现在的计算机学院。 计算机学院是全校规模大、综合实力强的 ...半岛在线注册报考信息 本站小编 半岛在线注册 2016-07-27