2006年北理計(jì)算機(jī)復(fù)試上機(jī)題_第1頁(yè)
2006年北理計(jì)算機(jī)復(fù)試上機(jī)題_第2頁(yè)
2006年北理計(jì)算機(jī)復(fù)試上機(jī)題_第3頁(yè)
2006年北理計(jì)算機(jī)復(fù)試上機(jī)題_第4頁(yè)
2006年北理計(jì)算機(jī)復(fù)試上機(jī)題_第5頁(yè)
已閱讀5頁(yè),還剩10頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

付費(fèi)下載

VIP免費(fèi)下載

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

2006年北理計(jì)算機(jī)復(fù)試上機(jī)題2009-09-1910:481.寫一個(gè)程序判斷字符串中數(shù)字的位置(不限制使用面向?qū)ο缶幊蹋├纾狠斎?/p>

a3b4c5

輸出

246

實(shí)現(xiàn):

#include<iostream>

#include<ctype.h>

usingnamespacestd;

intmain()

{

charc_arr[100];

inti,len=0;

cout<<"Pleaseenterastring:"<<endl;

cin>>c_arr;

while(c_arr[len++]);

cout<<c_arr<<endl;

for(i=0;i<len;i++)

{

if(isdigit(c_arr))

{

cout<<i+1<<"";

}

}

cout<<endl;

return0;

}

2.寫一個(gè)類,能接受int型的變量,接收變量后能存儲(chǔ)原變量(譬如12345)和其反向變量(54321),最多處理數(shù)量為10個(gè),當(dāng)輸入達(dá)到10個(gè)或者輸入變量為0的時(shí)候停止。并且在類銷毀前輸出存儲(chǔ)的所有變量。例如:輸入:12345,2234,0

輸出:12345

54321

22344322

實(shí)現(xiàn):

#include<iostream>

usingnamespacestd;

typedefstructs_store

{

intnum;

intreverseNum;

}s_store;

classCStore

{

public:

CStore(){};

~CStore(){};

voidsetS_st(intnum,intsub);

voidsetCount();

voidprint(intsub);

intgetCount();

protected:

private:

staticintcount;

s_stores_st[10];

};

intCStore::count=0;

intmain()

{

CStorecs;

intnum,size;

cout<<"Pleaseenteryourdata:"<<endl;

cin>>num;

cs.setS_st(num,cs.getCount());

cs.setCount();

//cout<<"countis:"<<cs.getCount()<<endl;

while(cs.getCount()<10)

{

cin>>num;

if(num==0)

{

break;

}

cs.setS_st(num,cs.getCount());

cs.setCount();

//cout<<"Inwhilecountis:"<<cs.getCount()<<endl;

}

size=cs.getCount();

//cout<<"sizeis:"<<size<<endl;

for(inti=0;i<size;i++)

{

cs.print(i);

cout<<endl;

}

return0;

}

voidCStore::setS_st(intnum,intsub)

{

s_st[sub].num=num;

intb=0,a;

while(num>0)

{

b*=10;

a=num%10;

b+=a;

num/=10;

}

s_st[sub].reverseNum=b;

}

voidCStore::setCount()

{

count++;

}

intCStore::getCount()

{

returncount;

}

voidCStore::print(intsub)

{

cout<<s_st[sub].num<<""<<s_st[sub].reverseNum;

}

3.寫一個(gè)CTriangle類,要求可以接受CTriangle(y,x)形式的構(gòu)造,創(chuàng)建在坐標(biāo)系中的直角三角形樣子如下A

|\

|

\

|

\

|

\B----------C三點(diǎn)的坐標(biāo)分別是A(0,y)B(0,0)C(x,0)實(shí)現(xiàn)+運(yùn)算,并且能夠處理鍵盤連續(xù)輸入若干個(gè)(少于十個(gè))三角形,并且連加(相加時(shí)候三角形邊長(zhǎng)長(zhǎng)度相加,方向同第一個(gè)三角形)。輸入0后結(jié)束并輸出最后得出的三角形的三個(gè)坐標(biāo)值。例如:

輸入:1

2

-1

-5

輸出:A(0,7),B(0,0),C(2,0)

實(shí)現(xiàn):

#include<iostream>

#include<cmath>

#include<iomanip>

usingnamespacestd;

classCTriangle

{

public:

CTriangle(doubley,doublex);

~CTriangle(){};

voidset(doubley,doublex);

voidaddTriangle();

voidprintShape();

voidprint();

protected:

private:

doublex;

doubley;

};

intmain()

{

CTrianglectrgle(10,-4),ctrgle1(10,4),ctrgle2(10,-4),ctrgle3(-10,-4);

ctrgle.printShape();

ctrgle.print();

ctrgle1.printShape();

ctrgle1.print();

ctrgle2.printShape();

ctrgle2.print();

ctrgle3.printShape();

ctrgle3.print();

ctrgle.addTriangle();

ctrgle.printShape();

return0;

}

CTriangle::CTriangle(doubley,doublex)

{

set(y,x);

}

voidCTriangle::set(doubley,doublex)

{

this->y=y;

this->x=x;

}

voidCTriangle::addTriangle()

{

set(0,0);

doubleyval,xval;

intcount=0;

boolxjudge=true,yjudge=true;

cout<<"Pleaseenterthevalues:"<<endl;

cin>>xval>>yval;

if(xval<0)

{

xjudge=false;

}

if(yval<0)

{

yjudge=false;

}

while(xval)

{

this->y+=abs(yval);

this->x+=abs(xval);

cin>>xval;

if(!xval)

{

break;

}

cin>>yval;

}

if(!xjudge)

{

this->x=(this->x)*(-1);

}

if(!yjudge)

{

this->y=(this->y)*(-1);

}

print();

}

voidCTriangle::printShape()

{

inti,num;

if(y>0&&x>0)

{

for(i=0;i<y;i++)

{

if((i+1)%2==0)

{

cout<<endl;

continue;

}

cout<<"|"<<setw(3*i/2+1)<<"\\"<<endl;

}

for(i=0;i<x*5;i++)

{

cout<<"-";

}

}

elseif(y<0&&x>0)

{

for(i=0;i<x*5;i++)

{

cout<<"-";

}

for(i=int(abs(y)-1);i>=0;i--)

{

if((i+1)%2==0)

{

cout<<endl;

continue;

}

cout<<"|"<<setw(3*i/2+1)<<"/"<<endl;

}

}

elseif(y>0&&x<0)

{

num=int(abs(y)-1);

for(i=num;i>=0;i--)

{

if((i+1)%2==0)

{

cout<<endl;

continue;

}

cout<<setw(3*i/2+4)<<"/"<<setw(num+4-(3*i/2))<<"|"<<endl;

}

cout<<endl;

for(i=0;i<abs(x*5);i++)

{

cout<<"-";

}

}

elseif(y<0&&x<0)

{

for(i=0;i<abs(x*5);i++)

{

cout<<"-";

}

cout<<endl;

num=int(abs(y));

for(i=0;i<abs(y);i++)

{

if((i)%2==0)

{

cout<<endl;

continue;

}

cout<<setw(3*i/2+1)<<"\\"<<setw(num+4-3*i/2)<<"|"<<endl;

}

}

cout<<endl;

}

voidCTriangle::print()

{

cout<<"A(0,"<<this->y<<"),B(0,0),C("

<<this->x<<",0)"<<endl;

}Timelimit:1Seconds

TotalSubmit:155

AcceptedSubmit:3題目要求:現(xiàn)有一筆經(jīng)費(fèi)可以報(bào)銷一定額度的發(fā)票。允許報(bào)銷的發(fā)票類型包括買圖書(shū)(A類)、文具(B類)、差旅(C類),要求每張發(fā)票的總額不得超過(guò)1000元,每張發(fā)票上,單項(xiàng)物品的價(jià)值不得超過(guò)600元?,F(xiàn)請(qǐng)你編寫程序,在給出的一堆發(fā)票中找出可以報(bào)銷的、不超過(guò)給定額度的最大報(bào)銷額。具體的輸入輸出格式規(guī)定如下:

輸入格式:測(cè)試輸入包含若干測(cè)試用例。每個(gè)測(cè)試用例的第1行包含兩個(gè)正數(shù)Q和N,其中Q是給定的報(bào)銷額度,N(<=30)是發(fā)票張數(shù)。隨后是N行輸入,每行的格式為:

mType_1:price_1Type_2:price_2...Type_m:price_m

其中正整數(shù)m是這張發(fā)票上所開(kāi)物品的件數(shù),Type_i和price_i是第i項(xiàng)物品的種類和價(jià)值。物品種類用一個(gè)大寫英文字母表示。當(dāng)N為0時(shí),全部輸入結(jié)束,相應(yīng)的結(jié)果不要輸出。輸出格式:對(duì)每個(gè)測(cè)試用例輸出1行,即可以報(bào)銷的最大數(shù)額,精確到小數(shù)點(diǎn)后2位。輸入樣例:

200.003

2A:23.50B:100.00

1C:650.00

3A:59.99A:120.00X:10.00

1200.002

2B:600.00A:400.00

1C:200.50

1200.503

2B:600.00A:400.00

1C:200.50

1A輸出樣例:

123.50

1000.00

1200.50題目描述:輸入:兩行

第一行:M和N

第二行:X

M和N是一個(gè)十進(jìn)制數(shù),M和N都在[2-35]之間,X是一個(gè)M進(jìn)制數(shù),X在[1-2*10^19]

輸出:一行

第一行:現(xiàn)在要求你將M進(jìn)制數(shù)X轉(zhuǎn)換成N進(jìn)制數(shù)輸出

注:A相當(dāng)于10,B相當(dāng)于11,Z相當(dāng)于35

輸入一:

1610

F

輸出一:

152009年山東大學(xué)計(jì)算機(jī)復(fù)試上機(jī)題目【網(wǎng)友回憶版】文章來(lái)源:勤思教育轉(zhuǎn)載請(qǐng)標(biāo)明出處和鏈接

,閱讀次數(shù):[103]次一共兩個(gè)題,每個(gè)50分,上機(jī)環(huán)境不限,編程語(yǔ)言不限,只要求結(jié)果,不要源代碼,數(shù)據(jù)隨機(jī)生成。題目均非準(zhǔn)確描述,但保持了原意

【1】輸入一個(gè)整數(shù),它可以由n(n>=2)個(gè)連續(xù)整數(shù)相加得到,輸出所有可能的連續(xù)整數(shù)序列,每個(gè)序列占一行,數(shù)字之間用空格分開(kāi),數(shù)據(jù)從小到大,每列按最小元素遞增順序排列,如果找不到,輸出none

例:21=1+2+3+4+5+6

21=6+7+8

則輸出123456

678

【2】某國(guó)設(shè)計(jì)了一種導(dǎo)彈防御系統(tǒng),但有缺陷,導(dǎo)彈來(lái)襲時(shí),第一枚炮彈可以達(dá)到任意高度,但以后的任意一炮均不能超過(guò)前一發(fā)炮彈高度?,F(xiàn)在僅有一套這樣的系統(tǒng)

輸入:來(lái)襲的導(dǎo)彈數(shù)目(不超過(guò)100枚)

輸出:1:能夠攔截的導(dǎo)彈數(shù)目30分

2:若要攔截所有導(dǎo)彈,需要幾套這樣的系統(tǒng)20分

其實(shí)第一問(wèn)就是找一個(gè)遞減序列的長(zhǎng)度,第二問(wèn)就是找一下有幾個(gè)這樣的遞減序列。

本次上機(jī)使用了一個(gè)考試系統(tǒng),要求先編好這兩個(gè)程序,然后輸入你的姓名,系統(tǒng)就會(huì)隨機(jī)生成兩個(gè)題目的輸入數(shù)據(jù),運(yùn)行后將結(jié)果在5分鐘內(nèi)輸入提交,否則時(shí)間用完,重新生成一組輸入數(shù)據(jù),最多有三次機(jī)會(huì)。

很遺憾,第一次使用這樣的東西,我得了0分。而且與編程無(wú)關(guān),反正編程我也不行,不過(guò)我得到的第一個(gè)數(shù)據(jù)實(shí)在比較簡(jiǎn)單:98

可以用筆算得到結(jié)果,無(wú)需程序。我分解對(duì)了,但填錯(cuò)位置了。(苦笑),第二個(gè)我也知道怎么弄,不過(guò)一著急,數(shù)錯(cuò)個(gè)數(shù)了。

希望師弟師妹吸取教訓(xùn)。第一題是給定一個(gè)程序,關(guān)于字符串的,要求輸入并調(diào)試,說(shuō)出此程序的意圖。意圖是按字母順序?qū)蓚€(gè)字符串比較排序。第二問(wèn)要求用盡可能少的語(yǔ)句對(duì)該程序進(jìn)行修改,使其能夠?qū)蓚€(gè)字符串比較長(zhǎng)度排序

實(shí)現(xiàn):

#include<iostream>

#include<string>

usingnamespacestd;

intmain()

{

stringstr1,str2;

cout<<"請(qǐng)輸入兩個(gè)字符串"<<endl;

cin>>str1>>str2;

if(str1<str2)

{

cout<<str2<<">"<<str1<<endl;

}

else

{

cout<<str1<<">"<<str2<<endl;

}

/*

if(str1.length()<str2.length())

{

cout<<str2<<"islongthan"<<str1<<endl;

}

else

{

cout<<str1<<"islongthan"<<str2<<endl;

}

*/

return0;

}第二題是要求編寫一個(gè)日期類,要求按xxxx-xx-xx的格式輸出日期,實(shí)現(xiàn)加一天的操作,不考慮閏年問(wèn)題,所有月份設(shè)為30天。本題黑盒測(cè)試時(shí),輸入2004年3月20日,得到加一天后時(shí)間為2004-3-21,能得一部分分?jǐn)?shù)。輸入2004年3月30日,得到加一天后時(shí)間為2004-4-1,能得一部分分?jǐn)?shù)。輸入2004年12月30日,得到加一天后時(shí)間為2005-1-1,且有時(shí)間越界處理,能得全部分?jǐn)?shù)。

實(shí)現(xiàn):

#include<iostream>

usingnamespacestd;

classd_date

{

public:

d_date();

~d_date(){};

voidsetD_date(intyear,intmonth,intday);

d_dateaddToD_date();

voidprint();

protected:

private:

intyear;

intmonth;

intday;

};

intmain()

{

intyear,month,day;

d_dated_dat;

while(true)

{

cout<<"請(qǐng)輸入年、月、日"<<endl;

cin>>year;

cin.ignore(2);

cin>>month;

cin.ignore(2);

cin>>day;

cin.ignore(2);

d_dat.setD_date(year,month,day);

d_dat=d_dat.addToD_date();

cout<<"加一天以后是:"<<endl;

d_dat.print();

}

return0;

}

d_date::d_date()

{

year=1900;

month=1;

day=1;

}

voidd_date::setD_date(intyear,intmonth,intday)

{

this->year=year;

if(month<0||month>12)

{

cout<<"對(duì)不起,您輸入的月份有誤,將自動(dòng)設(shè)置為1月"<<endl;

this->month=1;

}

else

this->month=month;

if(day<0||day>30)

{

cout<<"對(duì)不起,您輸入的日期有誤,將自動(dòng)設(shè)置為1日"<<endl;

this->day=1;

}

else

this->day=day;

}

d_dated_date::addToD_date()

{

day++;

if(day>30)

{

day=1;

month++;

}

if(month>12)

{

month=1;

year++;

}

return*this;

}

voidd_date::print()

{

cout<<this->year<<"-"<<this->month<<"-"<<this->day<<endl;

}

第三題要求編寫一個(gè)復(fù)數(shù)類,要求有4條。一是有構(gòu)造函數(shù),能對(duì)復(fù)數(shù)初始化。二是對(duì)復(fù)數(shù)c1,c2,c3.....能實(shí)現(xiàn)連加運(yùn)算,令c=c1+c2+c3+.....此處可以重載加法操作符。三是有函數(shù)實(shí)現(xiàn)兩個(gè)復(fù)數(shù)相加,并按照a+ib的形式輸出。四是能實(shí)現(xiàn)對(duì)一個(gè)復(fù)數(shù)c=a+ib,定義doublex=c有效,使x的值為實(shí)部和虛部之和。

實(shí)現(xiàn):

#include<iostream>

usingnamespacestd;

classPluralism

{

public:

Pluralism();

~Pluralism(){};

Pluralism&operator+(constPluralism&);

voidsetPluralism();

voidaddAnother(constPluralism&);

voidprint();

doublequalificatory();

protected:

private:

doublereal;

doublevain;

};

intmain()

{

Pluralismp_p1,p_p2,p_p3,p_p4;

cout<<"Entervaluelike13:"<<endl;

p_p1.setPluralism();

cout<<"p_p1is:";

p_p1.print();

p_p2.setPluralism();

cout<<"p_p2is:";

p_p2.print();

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論