字符串函数
length(S); //求S的长度
pos(p,s);//在S中找子串P
char:字符;
string:字符串;
———————————分—隔—线————————————
注意:以后每一题符合以下条件
——————————
| 时间限制:1秒 |
| 内存限制:128 MB |
——————————
———————————分—隔—线————————————
Problem A:键盘
题目描述
大家都知道,现在使用键盘的是下列字母:
qwertyuiop
asdfghjkl;
zxcvbnm,./
BSNY在练习盲打,但是有时候,他盲打会偏移一个,或者左偏或者
右偏,如果左偏,比如BSNY想打f,实际按了d;反之,如果右偏,想
打d,实际打了f。
为了方便,我们用L,R表示左偏和右偏。
给你BSNY打出来的字母,问BSNY原本想打的字母是什么?
输入
先输入L或R
然后一行字符
输出
输出BSNY原本想打的字符
样例输入
R
s;;upimrrfod;pbr
样例输出
allyouneedislove
提示
【数据规模和约定】
保证打的字符在上述键盘框内, 字符串长度小于10000
【参考程序(附解释)】
const
s='qwertyuiopasdfghjkl;zxcvbnm,./';//模拟键盘
var
x:char;
a:array[1..10000] of char;
q,t,i:longint;
begin
readln(x);
while not(eoln) do //读入打的字符
begin
inc(t);
read(a[t]);
end;
for i:=1 to t do //进行还原原打的字符
begin
q:=pos(a[i],s);
if x='R' then write(s[q-1])
else write(s[q+1]);
end;
end.
———————————分—隔—线————————————
Problem B 排序基础
【题目描述】
对n(n≤1000000)个数进行排序
【输入】
一个数n,第二行是一些乱七八糟的东西——N个数,不超过21000
00000
【输出】
也是一些乱七八糟的东西——排好序后的N个数
【样例输入】
4
5 2 3 4
【样例输出】
2 3 4 5
【分析】
这道题数据太大,用快速排序比较方便
【解答(附解释)】
var
i,n:longint;
a:array[1..1000000] of longint;
procedure qsort(l,r:longint); //快速排序
var
i,j,m,t:longint;
begin
i:=l;
j:=r;
m:=a[(l+r)div 2]; //☑中间数
repeat
while a[i]<m do i:=i+1; {如果左边数比中间数小,则
继续找}
while a[j]>m do j:=j-1;
if not(i>j) then
begin
t:=a[i]; //交换
a[i]:=a[j];
a[j]:=t;
i:=i+1; //继续找
j:=j-1;
end;
until i>j;
if l<j then qsort(l,j);
if i<r then qsort(i,r);
end;
begin
readln(n);
for i:=1 to n do
read(a[i]);
qsort(1,n);
for i:=1 to n do
if i<>n then write(a[i],' ')
else write(a[i]);
end.
———————————分—隔—线————————————
Problem C 2^N 的计算
题目描述
任意给定一个正整数N(N<=100),计算2的n次方的值。
输入
输入一个正整数N。
输出
输出2的N次方的值。
样例输入
5
样例输出
32
提示
高精度计算
【参考程序】
var
a:array[1..100]of longint;
i,j,len,n:longint;
begin
fillchar(a,sizeof(a),0);
readln(n);
a[1]:=1;len:=1;
for i:=1 to n do
begin
for j:=1 to len do
a[j]:=a[j]*2;
for j:=1 to len-1 do
if a[j]>=10 then
begin
a[j+1]:=a[j] div 10+a[j+1];
a[j]:=a[j] mod 10;
end;
while a[len]>=10 do
begin
a[len+1]:=a[len] div 10;
a[len]:=a[len]mod 10;
inc(len);
end;
end;
for i:=len downto 1 do write(a[i]);
writeln;
end.
———————————分—隔—线————————————
后记:由于作者技术有限,不能避免有一些错误。望各大读者可以
提出意见,我们会改正!