寻求oi竞赛试题解答

来源:百度知道 编辑:UC知道 时间:2024/06/17 00:38:27
编写一个译码程序,把一封英语信件译成数字代码。译码规则是以数字1代替字母A,数字2代替字母B,……,26代替字母Z,如遇空格则打印一个星号‘*’,英文信件以‘&‘结束。

C/C++版:

#include <stdio.h>
#include <string.h>

const int limitSize = 100000 + 1;

char c;

int main()
{
while ( true )
{
scanf("%c" , &c);
if ( c == '&' ) break;
if ( c == ' ' ) printf("*");
else printf("%d" , c - 'A' + 1);
}
return 0;
}

pascal版:
var
c : char;
begin
while (true) do
begin
read(c);
if ( c = '&' ) then break;
if ( c = ' ' ) then write('*')
else write( ord(c) - ord('A') + 1 );
end;
end.