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