前言:根据题意,是简单的字符串。所以只要暴力和模拟,注意细节问题。
P1055 ISBN号码 代码:
var
s:string;
i,j,n,m,k,l,t:longint;
v:char;
begin
readln(s);
delete(s,2,1);
delete(s,5,1);
delete(s,10,1);
for i:=1 to 9 do
t:=(ord(s[i])-48)*i+t;
case t mod 11 of
10:v:='X';
else v:=chr((t mod 11)+48);
end;
if s[10]=v then writeln('Right') else
writeln(s[1],'-',s[2],s[3],s[4],'-',s[5],s[6],s[7],s[8],s[9],'-',v);
end.
P1200 [USACO1.1]你的飞碟在这儿Your Ride Is He… 代码;
var
s1,s2:string;
t,i,a,b,l1,l2:longint;
j:char;
begin
readln(s1);
read(s2);
a:=1; b:=1;
l1:=length(s1);
l2:=length(s2);
for i:=1 to l1 do
begin
t:=1;
for j:='A' to 'Z' do
begin
if s1[i]=j then a:=a*t;
inc(t);
end;
end;
for i:=1 to l2 do
begin
t:=1;
for j:='A' to 'Z' do
begin
if s2[i]=j then b:=b*t;
inc(t);
end;
end;
if a mod 47=b mod 47 then write('GO')
else write('STAY');
end.
P1308 统计单词数 代码:
var
m,n,s:ansistring;
i,j,k,l,a,ans,t:longint;
f:boolean;
begin
readln(n);
readln(m);
f:=true;
m:=' '+m+' ';
for i:=1 to length(n) do
if n[i]<'a' then
n[i]:=chr(ord(n[i])+32);
for i:=1 to length(m) do
if m[i]=' ' then
begin
l:=i;
for j:=i+1 to length(m) do
if m[j]=' ' then
begin
a:=j; break;
end;
s:=copy(m,l+1,a-l-1);
for t:=1 to length(s) do
if s[t]<'a' then
s[t]:=chr(ord(s[t])+32);
if n=s then
begin
if f=true then
begin
k:=l; f:=false;
end;
inc(ans);
end;
end;
if ans=0 then write('-1');
if ans>0 then write(ans,' ',k-1);
end.
P1553 数字反转(升级版)代码:
总;将数字反转做成过程调用。
var
ss:string;
p:longint;
procedure try1(s:string);
var
i,l:longint;
begin
if s[1]='-' then
begin
write('-');
delete(s,1,1);
end;
l:=length(s);
while (s[l]='0') and (l>1) do dec(l);
for i:=l downto 1 do
write(s[i]);
end;
procedure try2(s:string);
var
i,l,r:longint;
begin
if s[1]='-' then
begin
write('-');
delete(s,1,1);
end;
l:=length(s); r:=1;
while (s[l]='0') and (l>1) do dec(l);
while (s[r]='0') and (r<l) do inc(r);
for i:=l downto r do
write(s[i]);
end;
begin
readln(ss);
p:=pos('.',ss);
if p>0 then
begin
try1(copy(ss,1,p-1));
write('.');
try2(copy(ss,p+1,length(ss)-p)); exit;
end;
p:=pos('/',ss);
if p>0 then
begin
try1(copy(ss,1,p-1));
write('/');
try2(copy(ss,p+1,length(ss)-p)); exit;
end;
p:=pos('%',ss);
if p>0 then
begin
try1(copy(ss,1,p-1));
write('%'); exit;
end;
try1(ss);
end.
P1598 垂直柱状图
总:注意输出。
var
s1,s2,s3,s4:string;
max,min:longint;
a:array [1..26] of longint;
procedure init;
var
i:longint;
begin
max:=0; min:=10000;
fillchar(a,sizeof(a),0);
readln(s1); readln(s2); readln(s3); readln(s4);
for i:=1 to length(s1) do
if s1[i] in ['A'..'Z'] then
a[ord(s1[i])-64]:=a[ord(s1[i])-64]+1;
for i:=1 to length(s2) do
if s2[i] in ['A'..'Z'] then
a[ord(s2[i])-64]:=a[ord(s2[i])-64]+1;
for i:=1 to length(s3) do
if s3[i] in ['A'..'Z'] then
a[ord(s3[i])-64]:=a[ord(s3[i])-64]+1;
for i:=1 to length(s4) do
if s4[i] in ['A'..'Z'] then
a[ord(s4[i])-64]:=a[ord(s4[i])-64]+1;
end;
procedure print;
var
i,j,t:longint;
f:boolean;
begin
for i:=1 to 26 do
begin
if a[i]>max then max:=a[i];
if a[i]<min then min:=a[i];
end;
if min=0 then min:=1;
for i:=max downto min do
begin
for j:=26 downto 1 do
if a[j]>=i then
begin
t:=j; break;
end;
f:=true;
for j:=1 to 26 do
if (a[j]>=i) and (j<=t) then
if not f then write (' *')
else begin f:=false; write ('*'); end
else if j<=t then write (' ');
writeln;
end;
f:=true;
for i:=1 to 26 do
begin
if not f then write (' ') else f:=false;
write (chr(i+64));
end;
end;
begin
init;
print;
end.
P1914 小书童——密码
var
n,i,x:longint;
s:string;
begin
readln(n);
n:=n mod 26;
readln(s);
for i:=1 to length(s) do
begin
x:=(ord(s[i])-97+n) mod 26;
write(chr(x+97));
end;
end.