您的位置:首页 > 其它

普及练习场之简单的模拟

2017-02-03 19:38 477 查看
前言:如标题所说。

P1003 铺地毯

总:look前言。

var
s,n,m,t,p:longint;
a,b,x,y:array [1..10001] of longint;
begin
readln(s);
for t:=1 to s do
readln(a[t],b[t],x[t],y[t]);
readln(n,m); p:=0;
for t:=1 to s do
if (n>=a[t]) and (n<=a[t]+x[t]) and (m>=b[t]) and (m<=b[t]+y[t]) then p:=t;
if p=0 then write('-1')
else write(p);
end.


P1017 进制转换

总:同上。

const
ss='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
var
n,x,i,m:longint;
s:string;
begin
readln(n,x);
m:=n; s:='';
repeat
i:=m mod x; m:=m div x;
if i<0 then
begin
i:=i-x;
m:=m+1;
end;
s:=ss[i+1]+s;
until m=0;
writeln(n,'=',s,'(base',x,')');
end.


总:同上,注意情况。

P1067 多项式输出

var
n,s,i:longint;
begin
readln(n);
for i:=1 to n+1 do
begin
read(s);
if s=0 then continue;
if s<0 then write('-');
if (i>1)and(s>0) then write('+');
if (abs(s)>1) or (i=n+1) then write(abs(s));
if i<n+1 then
begin
write('x');
if (i<n) then write('^',n-i+1);
end;
end;
end.


P1540 机器翻译

总:开个数组记录,然后…模拟。

var
q:array[0..10000]of longint;
m,n,x,i,j:longint;
head,tail,ans:longint;
f:boolean;
begin
readln(m,n);
head:=1; tail:=0; ans:=0;
for i:=1 to n do
begin
read(x); f:=false;
for j:=head to tail do
if x=q[j] then
begin
f:=true; break
end;
if f then continue;
inc(tail); q[tail]:=x; inc(ans);
if ans>m then inc(head);
end;
write(ans);
end.


P1056 排座椅

点击:排座椅题解

P1125 笨小猴

总:将字母大写化(小写化也行),用数组统计,暴力max and min,判断质数。

var
s:string;
l,i,j,max,min,k:longint;
a:array ['A'..'Z'] of longint;
t:char;
f:boolean;
begin
readln(s);
l:=length(s);
for i:=1 to l do
begin
s[i]:=upcase(s[i]);
inc(a[s[i]]);
end;
max:=0; min:=maxlongint;
for t:='A' to 'Z' do
begin
if (max<a[t]) and (a[t]<>0) then max:=a[t];
if (min>a[t]) and (a[t]<>0) then min:=a[t];
end;
k:=max-min;
if k<=1 then
begin
writeln('No Answer');
write('0');
exit;
end;
f:=true;
for i:=2 to trunc(sqrt(k)) do
if k mod i=0 then begin f:=false; break; end;
if f=true then
begin
writeln('Lucky Word');
write(k);
end else
begin
writeln('No Answer');
write('0');
end;
end.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息