华东师范大学计算机机试真题.docx

上传人:b****3 文档编号:5457726 上传时间:2022-12-16 格式:DOCX 页数:73 大小:37.88KB
下载 相关 举报
华东师范大学计算机机试真题.docx_第1页
第1页 / 共73页
华东师范大学计算机机试真题.docx_第2页
第2页 / 共73页
华东师范大学计算机机试真题.docx_第3页
第3页 / 共73页
华东师范大学计算机机试真题.docx_第4页
第4页 / 共73页
华东师范大学计算机机试真题.docx_第5页
第5页 / 共73页
点击查看更多>>
下载资源
资源描述

华东师范大学计算机机试真题.docx

《华东师范大学计算机机试真题.docx》由会员分享,可在线阅读,更多相关《华东师范大学计算机机试真题.docx(73页珍藏版)》请在冰豆网上搜索。

华东师范大学计算机机试真题.docx

华东师范大学计算机机试真题

2009机试

计算和的数位

Sumofdigit

Description

Writeaprogramwhichcomputesthedigitnumberofsumoftwointegersaandb.

Input

Thefirstlineofinputgivesthenumberofcases,N(1≤N≤100).Ntestcasesfollow.

Eachtestcaseconsistsoftwointegersaandbwhichareseparetedbyaspaceinaline.(0<=a,b<=100000000).

Output

Foreachtestcase,printthenumberofdigitsofa+b.

SampleInput

3

57

199

1000999

SampleOutput

2

3

4

#include

intmain()

{

intn;

inta,b;

intsum;

while(scanf("%d",&n)!

=EOF)

{

while(n--)

{

intan=0;

scanf("%d%d",&a,&b);

sum=a+b;

while(sum)

{

an++;

sum/=10;

}

printf("%d\n",an++);

}

}

return0;

}

大写改小写

Capitalize

Description

Writeaprogramwhichreplaceallthelower-caselettersofagiventextwiththecorrespondingcaptitalletters.

Input

Atextincludinglower-caseletters,periods,andspace.

Output

OutputTheconvertedtext.

SampleInput

welcometoeastchinanormaluniversity.

SampleOutput

WELCOMETOEASTCHINANORMALUNIVERSITY.

#include

#include

charstr[1000];

intmain()

{

intl;

while(gets(str))

{

l=strlen(str);

inti;

for(i=0;i

{

if(str[i]>='a'&&str[i]<='z')

printf("%c",str[i]-32);

else

printf("%c",str[i]);

}

printf("\n");

}

return0;

}

素数对

PrimesPair

Description

Wearrangethenumbersbetween1andN(1<=N<=10000)inincreasingorderanddecreasingorderlikethis:

123456789...N

N...987654321

Twonumbersfacedeachotherformapair.YourtaskistocomputethenumberofpairsPsuchthatbothnumbersinthepairsareprime.

Input

Thefirstlineofinputgivesthenumberofcases,C(1≤C≤100).Ctestcasesfollow.

EachtestcaseconsistsofanintegerNinoneline.

Output

Foreachtestcase,outputP.

SampleInput

4

1

4

7

51

SampleOutput

0

2

2

6

#include

#include

boolprime[10005];

voidinit()

{

inti;

intj;

prime[0]=prime[1]=false;//不是素数

prime[2]=true;//是素数

for(i=3;i<=10005;i+=2)

{

prime[i]=true;//是素数

prime[i+1]=false;//不是素数除0和2之外的偶数都不是素数

}

for(i=3;i<=10005;i+=2)

{

if(prime[i]==true)//是素数

{

j=i+i;

while(j<=10005)

{

prime[j]=false;//不是素数

j+=i;

}

}

}

}

intmain()

{

intc;

intn;

init();//初始化

while(scanf("%d",&c)!

=EOF)

{

while(c--)

{

scanf("%d",&n);

intsum=0;

inti;

for(i=2;i<=n/2;i++)

{

if(prime[i]==true&&prime[n+1-i]==true)

sum++;

}

sum*=2;

if(n%2==1)//n为奇数

{

if(prime[n/2+1]==true)

sum+=1;

}

printf("%d\n",sum);

}

}

return0;

}

求最大公约数和最小公倍数

GCDandLCM

Description

Writeaprogramwhichcomputesthegreatestcommondivisor(GCD)andtheleastcommonmultiple(LCM)ofgivenaandb(0

Input

Thefirstlineofinputgivesthenumberofcases,N(1≤N≤100).Ntestcasesfollow.

Eachtestcasecontainstwointergeraandbseparatedbyasinglespaceinaline.

Output

Foreachtestcase,printGCDandLCMseparatedbyasinglespaceinaline.

SampleInput

2

86

50003000

SampleOutput

224

100015000

#include

intgetgcd(inta,intb)

{

intgcd;

intt1,t2;

t1=a;

t2=b;

gcd=t1%t2;

while(gcd!

=0)

{

t1=t2;

t2=gcd;

gcd=t1%t2;

}

returnt2;

}

intmain()

{

intn;

inta,b;

while(scanf("%d",&n)!

=EOF)

{

while(n--)

{

scanf("%d%d",&a,&b);

printf("%d%d\n",getgcd(a,b),a*b/(getgcd(a,b)));

}

}

return0;

}

排序后求位置处的数

Sortit…

Description

Thereisadatabase,partychenwantyoutosortthedatabase’sdataintheorderfromtheleastuptothegreatestelement,thendothequery:

"Whichelementisi-thbyitsvalue?

"-withibeinganaturalnumberinarangefrom1toN.

Itshouldbeabletoprocessquicklyquerieslikethis.

Input

Thestandardinputoftheproblemconsistsoftwoparts.Atfirst,adatabaseiswritten,andthenthere'sasequenceofqueries.Theformatofdatabaseisverysimple:

inthefirstlinethere'sanumberN(1<=N<=100000),inthenextNlinestherearenumbersofthedatabaseoneineachlineinanarbitraryorder.Asequenceofqueriesiswrittensimplyaswell:

inthefirstlineofthesequenceanumberofqueriesK(1<=K<=100)iswritten,andinthenextKlinestherearequeriesoneineachline.Thequery"Whichelementisi-thbyitsvalue?

"iscodedbythenumberi.

Output

TheoutputshouldconsistofKlines.Ineachlinethereshouldbeananswertothecorrespondingquery.Theanswertothequery"i"isanelementfromthedatabase,whichisi-thbyitsvalue(intheorderfromtheleastuptothegreatestelement).

SampleInput

5

7

121

123

7

121

3

3

2

5

SampleOutput

121

7

123

#include

#include

usingnamespacestd;

intnum[100010];

intpos[105];

intmain()

{

intn;

inti;

intk;

while(scanf("%d",&n)!

=EOF)

{

for(i=1;i<=n;i++)

scanf("%d",&num[i]);

scanf("%d",&k);

for(i=1;i<=k;i++)

scanf("%d",&pos[i]);

sort(num+1,num+1+n);

for(i=1;i<=k;i++)

printf("%d\n",num[pos[i]]);

}

return0;

}

*路由器连接

HubConnectionplan

Description

Partychenisworkingassystemadministratorandisplanningtoestablishanewnetworkinhiscompany.TherewillbeNhubsinthecompany,theycanbeconnectedtoeachotherusingcables.Sinceeachworkerofthecompanymusthaveaccesstothewholenetwork,eachhubmustbeaccessiblebycablesfromanyotherhub(withpossiblysomeintermediatehubs).

Sincecablesofdifferenttypesareavailableandshorteronesarecheaper,itisnecessarytomakesuchaplanofhubconnection,thatthecostisminimal.partychenwillprovideyouallnecessaryinformationaboutpossiblehubconnections.Youaretohelppartychentofindthewaytoconnecthubssothatallaboveconditionsaresatisfied.

Input

Thefirstlineoftheinputcontainstwointegernumbers:

N-thenumberofhubsinthenetwork(2<=N<=1000)andM-thenumberofpossiblehubconnections(1<=M<=15000).Allhubsarenumberedfrom1toN.ThefollowingMlinescontaininformationaboutpossibleconnections-thenumbersoftwohubs,whichcanbeconnectedandthecablecostrequiredtoconnectthem.costisapositiveintegernumberthatdoesnotexceed106.Therewillalwaysbeatleastonewaytoconnectallhubs.

Output

Outputtheminimizecostofyourhubconnectionplan.

SampleInput

46

121

131

142

231

341

241

SampleOutput

3

#include

#include

usingnamespacestd;

structEdge{

inta,b;

intcost;

}E[15010];

intTree[1010];

intfindRoot(intx)

{

if(Tree[x]==-1)

returnx;

else

{

inttmp=findRoot(Tree[x]);

Tree[x]=tmp;

returntmp;

}

}

boolCmp(Edgea,Edgeb)

{

returna.cost

}

intmain()

{

intn;

intm;

inti;

while(scanf("%d",&n)!

=EOF)

{

scanf("%d",&m);

for(i=1;i<=m;i++)

scanf("%d%d%d",&E[i].a,&E[i].b,&E[i].cost);

sort(E+1,E+1+m,Cmp);//排序

for(i=1;i<=n;i++)

Tree[i]=-1;

intans=0;

for(i=1;i<=m;i++)

{

inta=findRoot(E[i].a);

intb=findRoot(E[i].b);

if(a!

=b)

{

Tree[a]=b;

ans+=E[i].cost;

}

}

printf("%d\n",ans);

}

return0;

}

*编译原理

PrinciplesofCompiler

Description

AfterlearntthePrinciplesofCompiler,partychenthoughtthathecansolveasimpleexpressionproblem.Sohegiveyoustringsoflessthan100characterswhichstrictlyadheretothefollowinggrammar(giveninEBNF):

A:

='('B')'|'x'.

B:

=AC.

C:

={'+'A}.

Canyousolvethemtoo?

Input

Thefirstlineofinputgivesthenumberofcases,N(1≤N≤100).Ntestcasesfollow.

ThenextNlineswilleachcontainastringasdescribedabove.

Output

Foreachtestcase,iftheexpressionisadapttotheEBNFaboveoutput“Good”,elseoutput“Bad”.

SampleInput

3

(x)

(x+(x+x))

()(x)

SampleOutput

Good

Good

Bad

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

usingnamespacestd;

charex[110];

intindex;

boolA();

boolB();

boolC();

boolA()

{

if(ex[index]=='x')

{

index++;

while(ex[index]=='')index++;

returntrue;

}

if(ex[index]=='(')

{

index++;

while(ex[index]=='')index++;

if(B()&&ex[index]==')')

{

index++;

while(ex[index]=='')index++;

returntrue;

}

}

returnfalse;

}

boolB()

{

returnA()&&C();

}

boolC()

{

while(ex[index]=='+')

{

index++;

while(ex[index]=='')index++;

//returnA();

if(!

A())

returnfalse;

}

returntrue;

}

intmain()

{

intN;

scanf("%d",&N);

getchar();

while(N--)

{

gets(ex);

index=0;

printf("%s\n",A()&&ex[index]=='\0'?

"Good":

"Bad");

}

return0;

}

*分开连接

SeparateConnections

Description

Partychenareanalyzingacommunicationsnetworkwithatmost18nodes.Characterinamatrixi,j(i,jboth0-based,asmatrix[i][j])denoteswhethernodesiandjcancommunicate('Y'foryes,'N'forno).Assuminganodecannotcommunicatewithtwonodesatonce,returnthemaximumnumberofnodesthatcancommunicatesimultaneously.Ifnodeiiscommunicatingwithnodejthennodejiscommunicatingwithnodei.

Input

Thefirstlineofinputgivesthenumberofcases,N(1≤N≤100).Ntestcasesfollow.

Ineachtestcase,thefirstlineisthenumberofnodesM(1≤M≤18),thenthereareagridbyM*Mdescribledthematrix.

Output

Foreachtestcase,outputthemaximumnumberofnodesthatcancommunicatesimultaneously

SampleInput

2

5

NYYYY

YNNNN

YNNNN

YNNNN

YNNNN

5

NYYYY

YNNNN

YNNNY

YNNNY

YNYYN

SampleOutput

2

4

Hint

Thefirsttestcase:

Allcommunicationsmustoccurwithnode0.Sincenode0canonlycommunicatewith1nodeatatime,theoutputvalueis2.

Thesecondtestcase:

Inthissetup,wecanletnode0communicatewithnode1,andnode3communicatewithnode4.

#include

#i

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 医药卫生 > 基础医学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1