奥林匹克信息学选题及解答.docx

上传人:b****0 文档编号:17536028 上传时间:2023-07-26 格式:DOCX 页数:34 大小:31.77KB
下载 相关 举报
奥林匹克信息学选题及解答.docx_第1页
第1页 / 共34页
奥林匹克信息学选题及解答.docx_第2页
第2页 / 共34页
奥林匹克信息学选题及解答.docx_第3页
第3页 / 共34页
奥林匹克信息学选题及解答.docx_第4页
第4页 / 共34页
奥林匹克信息学选题及解答.docx_第5页
第5页 / 共34页
奥林匹克信息学选题及解答.docx_第6页
第6页 / 共34页
奥林匹克信息学选题及解答.docx_第7页
第7页 / 共34页
奥林匹克信息学选题及解答.docx_第8页
第8页 / 共34页
奥林匹克信息学选题及解答.docx_第9页
第9页 / 共34页
奥林匹克信息学选题及解答.docx_第10页
第10页 / 共34页
奥林匹克信息学选题及解答.docx_第11页
第11页 / 共34页
奥林匹克信息学选题及解答.docx_第12页
第12页 / 共34页
奥林匹克信息学选题及解答.docx_第13页
第13页 / 共34页
奥林匹克信息学选题及解答.docx_第14页
第14页 / 共34页
奥林匹克信息学选题及解答.docx_第15页
第15页 / 共34页
奥林匹克信息学选题及解答.docx_第16页
第16页 / 共34页
奥林匹克信息学选题及解答.docx_第17页
第17页 / 共34页
奥林匹克信息学选题及解答.docx_第18页
第18页 / 共34页
奥林匹克信息学选题及解答.docx_第19页
第19页 / 共34页
奥林匹克信息学选题及解答.docx_第20页
第20页 / 共34页
亲,该文档总共34页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

奥林匹克信息学选题及解答.docx

《奥林匹克信息学选题及解答.docx》由会员分享,可在线阅读,更多相关《奥林匹克信息学选题及解答.docx(34页珍藏版)》请在冰点文库上搜索。

奥林匹克信息学选题及解答.docx

奥林匹克信息学选题及解答

Addtionofnumbers

TimeLimit:

2seconds

EriciscurrentlystudyinginPrimarytwo.Hewasaskedtodon(1

 n

20)additionproblems,whichistosumuptwointegers,aandb(1

 a,b<231).Hehastohandthisintomorrow.However,heisaverylazystudent.Hewantstoplaylegoinsteadofdoingthishomework.YouareEric'selderbrotherandheaskyoutohelphim.Asbothofyouarelazyguys,youdecidetowriteaprogramtocompletethistaskratherthancalculatingthosebyhand.

Input

Theinputcontainsn+1linesofinput.Thefirstlineoftheinputisthenumbern.Thesecondlinetothen+1thlinecontainstwonumbersaandbateachline.

Output

Theoutputfilecontainsnlines,whicharethesumofaandb.Thei-thlineofoutputisthesumofthetwointegersinthei+1-thlineofinput.

SampleInput

5

11

29

36

419

5200

SampleOutput

2

11

9

23

205

programaddlist(input,output);

var

a:

array[1..20]ofinteger;

b:

array[1..20]ofinteger;

n:

integer;

i,j:

integer;

begin

readln(n);

fori:

=1tondoreadln(a[i],b[i]);

fori:

=1tondowriteln(a[i]+b[i]);

{*readln();*}

end.

计算a^bmodc

1<=b,c<=10^9

输入:

abc

输出:

求出的值

programmimod(input,output);

var

a:

integer;

b:

integer;

c:

integer;

i,j:

integer;

ret:

longint;

begin

readln(a,b,c);

ret:

=1;

fori:

=1tobdoret:

=ret*a;

writeln(retmodc);

readln();

end.

The`if'statement

TimeLimit:

1second

MemoryLimit:

1MB

Writeaprogramtoreadinanintegern(0

Input

Theinputfilecontainsanintegern.

Output

Theoutputcontains1line,whichistheresultoftheabovedescription.

SampleInput

24

SampleOutput

48

programifsolution(input,output);

var

n:

int64;

begin

readln(n);

if(nmod2=1)and(n>50)and(n<100)then

writeln(n)

elseif(nmod6=0)or(nmod7=0)then

writeln(2*n)

else

writeln(3*n);

readln();

end.

AlphabetSorting

TimeLimit:

1second

MemoryLimit:

1MB

Alleniscurrentlystudyingthe26letters.Pleasewriteaprogramtohelphimtoidentifythe10thletter,aftersortinginascendingorder,intheinput.

Input

Theinpuefilecontainsn+1lines.Thefirstlinecontainsanintegern(11

n

26).Eachofthefollowingnlinescontainalowercaseletter.

Output

Theoutputcontainsthe10thletteraftersortinginascendingorder.

SampleInput

11

a

c

b

e

f

d

g

z

h

i

x

SampleOutput

x

programalphabetsort(input,output);

var

a:

array[1..26]ofchar;

temp:

char;

n:

integer;

i,j:

integer;

begin

readln(n);

fori:

=1tondoreadln(a[i]);

fori:

=1tondo

forj:

=i+1tondo

begin

ifa[i]>a[j]then

begin

temp:

=a[i];

a[i]:

=a[j];

a[j]:

=temp;

end;

end;

writeln(a[10]);

readln();

end.

TakingSquareRoots

TimeLimit:

1second

Givenalistofintegers,outputtheresultaftertakingthesquarerootsroundedupto3decimalplaces.Thefirstlineofinputconsistsofonenon-negativeintegerN,whichissmallerthan21,whichindicatesthenumberoftestcases.ThefollowingNlinescontainanintegerineachline,whichliesbetween-40000and40000.Outputitssquarerootupto3decimalplaces.Ifthesquarerootisnotreal,youshoulddisplay`i'afterthenumber.

SampleInput

2

4

-4

SampleOutput

2.000

2.000i

programsqrtA(input,output);

var

n:

int64;

a:

array[1..20]ofinteger;

i:

integer;

isnegative:

boolean;

ret:

real;

begin

readln(n);

fori:

=1tondoreadln(a[i]);

fori:

=1tondo

begin

isnegative:

=(a[i]<0);

ret:

=sqrt(abs(a[i]));

write(ret:

0:

3);

ifisnegativethenwrite('i');

writeln;

end;

readln();

end.

OutputYourMessage

TimeLimit:

1second

MemoryLimit:

1MB

Givenanameintheinput,pleaseoutputthenamewithanadditionalstring`,youarefired.'Iftheinputiseither`Marcus',`Patrick'or`Sherman'(thesetheeenamesaresortedinlexicographicalorder),pleaseoutputhisnameand`isextremelyclever.'.Itisguranteedthatthestringintheinputcontainsatmost255charactersandthecharactersareallprintableASCIIcharacters.

SampleInput1

Simon

SampleOutput1

Simon,youarefired.

SampleInput2

Patrick

SampleOutput2

Patrickisextremelyclever.

SampleInput3

Sherman

SampleOutput3

Shermanisextremelyclever.

programabc;

varwhoname:

string;

functionIsClever(yourname:

string):

boolean;

begin

IsClever:

=(yourname='Marcus')or(yourname='Patrick')or(yourname='Sherman');

end;

begin

readln(whoname);

ifIsClever(whoname)then

writeln(whoname,'isextremelyclever.')

else

writeln(whoname,',youarefired.');

end.

Sherman'sWebsite

TimeLimit:

3seconds

Shermanisanexperiencedwebsitedesigner.Hebuiltafamouswebsite,comfield,whichattractsmillionsofvisitorstobrowsehiswebsiteperday.Thiswebsiteprovidesawidevarietyofservices,games,articlesandevenonlinejudgefortheusers.ItisextremelypopularandnearlyeveryHongKongpeopleknowhiswebiste.MarcusandPatrickarehisfansandtheypostalotofthreadsinhisforum.Hecurrentlyhas2147483647threadsinhisforum!

Shermanwantstopostsomestatisticsofhiswebsitetoprovethathiswebsiteisreallypopular.Hewantstodosomestatisticalanalysis.Fromhisserversoftware,heknowsthatthenumberofvisitorsofhiswebsiteperhour.However,hedoesnotknowmuchaboutstatisticsasheistooyoungtolearnit.AsafriendofSherman,youhavetheresponsibilitytohelphim.

Givenaspecifiedtimeperiod,andthenumberofvisitorsperhour,writeaprogramwhichtellshimthemeanandmedianofthesestatistics.

Input

TheinputfileconsistsofN+1lines.ThefirstlinecontainsanintegerN(1

N

100000),whichisthenumberofhoursprovidedinthestatistics.The2ndtotheN+1thlinearethenumberofvisitorsperhour,whicharenon-negativeintegerslessthan21475.

Output

Theoutputfileshouldcontain3lines.Thefirstlinecontainsthetimeperiod,indays,inthisstatisticalreport.Onedayisaddediftheexceedinghourscannotformanewday.Thesecondlineofoutputisthemean(correcttothreedecimalplaces)andthethirdlineisthemedian(correcttothenearestinteger).Youshouldfollowtheoutputformatasshowninthesampleoutput.

SampleInput

5

1

2

3

4

5

SampleOutput

1day(s)

Mean:

3.000

Median:

3

programwebsite(input,output);

var

n:

integer;

a:

array[1..100000]ofinteger;

i,j:

integer;days:

integer;

mean:

real;median:

integer;

totals:

int64;temp:

real;

dis:

array[1..100000]ofreal;

pos:

integer;

begin

readln(n);

fori:

=1tondoreadln(a[i]);

days:

=ndiv24;

ifnmod24>0thendays:

=days+1;

totals:

=0;

fori:

=1tondototals:

=totals+a[i];

mean:

=totals/n;

fori:

=1tondodis[i]:

=Abs(a[i]-mean);

fori:

=1tondo

forj:

=i+1tondo

begin

ifdis[i]>dis[j]then

begin

temp:

=dis[i];

dis[i]:

=dis[j];

dis[j]:

=temp;

end;

end;

fori:

=1tondo

begin

ifabs(a[i]-mean)=dis[1]then

begin

pos:

=i;

median:

=a[pos];

break;

end;

end;

writeln(days,'day(s)');

writeln('Mean:

',mean:

0:

3);

writeln('Median:

',median);

readln();

end.

返回数A在数组中的位置

输入格式:

数A,一维数组B的元素个数N(N<=10^5)

已按升序或降序排列的一维数组B(-32768

输出格式:

数A在B中的下标。

B中如果存在多个A,则输出最小的一个。

如果B中不存在A,则输出-1

输入样例:

36

1334510

输出样例:

2

输入样例:

13

345

输出样例:

-1

programarrayloc(input,output);

var

a:

integer;

b:

array[1..100000]ofinteger;

n:

integer;

i,pos:

integer;

begin

readln(a,n);

fori:

=1tondoread(b[i]);

readln();

pos:

=-1;

fori:

=1tondo

begin

if(b[i]=a)then

begin

pos:

=i;

break;

end;

end;

writeln(pos);

readln();

end.

闰年

(二)

输入任意两个年份(正整数),判断这两个年份之间共存在多少个闰年?

输入样例:

1981 2000

输出样例:

5

programleapyear(input,output);

var

a:

integer;

b:

integer;

n,i:

integer;

begin

readln(a,b);

n:

=0;

fori:

=atobdo

begin

if((imod4=0)and(imod100>0))or(imod400=0)thenn:

=n+1;

end;

writeln(n);

readln();

end.

进制转换

(二)

输入K进制的正整数N,请把N化为L进制后输出。

(N<1000000;L,K<=16)

有多组数据。

输入格式:

KNL

输入样例:

810 2

101016

输出样例:

1000

A

programhextrans(input,output);

var

sin,sout:

string;

x:

integer;

k,n,l:

integer;

ac:

array[0..15]ofchar=('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');

ca:

array[char]ofinteger;

c:

char;

i:

integer;

len:

integer;

functionpower(j,k:

integer):

integer;

vartemp,i:

integer;

begin

temp:

=1;

fori:

=1tojdotemp:

=temp*k;

power:

=temp;

end;

begin

forc:

='0'to'9'doca[c]:

=ord(c)-ord('0');

forc:

='A'to'F'doca[c]:

=ord(c)-ord('A')+10;

readln(k,n,l);

x:

=0;

str(n,sin);

len:

=length(sin);

fori:

=lendownto1dox:

=x+ca[sin[i]]*power(len-i,k);

sout:

='';

whilex>0do

begin

sout:

=ac[xmodl]+sout;

x:

=xdivl;

end;

writeln(sout);

readln();

end.

题目:

剔除多余括号(reduce.pas)

输入一个含有括号的四则运算表达式,可能含有多余的括号。

编程整理该表达式,去掉所有多余的括号,原表达式中所有变量和运算符相对位置保持不变,并保持与原表达式等价。

变量用小写的a-z表示,运算符为+,-,*,/

例:

输入表达式应输出表达式

a+(b+c)a+b+c

(a*b)+c/da*b+c/d

a+b/(c-d)a+b/(c-d)

注意输入a+b时不能输出b+a

表达式以字符串输入,长度不超过255。

输入不用判错。

所有变量为单个小写字母。

只是要求去掉所有多余括号,不要求对表达式化简。

programreduce(input,output);

var

i,j,k,n,l:

integer;

s:

string;

a:

array[0..256]ofinteger;

c:

array[1..100]ofinteger;

functionok:

boolean;

vark,t:

integer;

btt,f:

boolean;

begin

ok:

=false;

if((s[i-1]in['+','('])or(i=1))and((s[j+1]in['+','-',')'])or(j=l))thenexit(true);

ifs[i-1]='/'thenexit(false);

btt:

=true;t:

=1000;f:

=true;

fork:

=i+1toj-1doifbttthen

if(a[k]<>0)and(t=1000)thenbegin

f

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

当前位置:首页 > 农林牧渔 > 林学

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2