华东师范大学计算机机试真题.docx
《华东师范大学计算机机试真题.docx》由会员分享,可在线阅读,更多相关《华东师范大学计算机机试真题.docx(72页珍藏版)》请在冰豆网上搜索。
![华东师范大学计算机机试真题.docx](https://file1.bdocx.com/fileroot1/2022-10/12/f9a41793-f858-48ee-a3f6-f8f5a5f7f900/f9a41793-f858-48ee-a3f6-f8f5a5f7f9001.gif)
华东师范大学计算机机试真题
华东师范大学计算机机试真题
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(0Input
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++