Pascal 帕斯卡输入法

Pascal 帕斯卡输入法,pascal,Pascal,我是一个初学者,目前我很享受竞争性编程作为一种学习方式。 我的任务是输入一个单词列表并加密输出。 我的算法运行得很好,但我的问题在于我输入姓名列表的方式。 我不知道是否可以将问题的链接放入,但我必须输入一次: 4 word localization internationalization pneumonoultramicroscopicsilicovolcanoconiosis 然后得到这个结果 word l10n i18n p43s 但是我唯一能做的就是一个接一个地给名字,有没有一种方法

我是一个初学者,目前我很享受竞争性编程作为一种学习方式。 我的任务是输入一个单词列表并加密输出。 我的算法运行得很好,但我的问题在于我输入姓名列表的方式。 我不知道是否可以将问题的链接放入,但我必须输入一次:

4
word
localization
internationalization
pneumonoultramicroscopicsilicovolcanoconiosis
然后得到这个结果

word
l10n
i18n
p43s
但是我唯一能做的就是一个接一个地给名字,有没有一种方法可以把所有的东西都输入一次,而不把它看成一个固定的字符串

这是我的剧本:

program A71;
uses wincrt;
var
    word: String;

function correctname(word : String): Boolean;
var
    i : Integer;
begin
    correctname:= true;
    for i:=1 to length(word) do 
        if not (upcase(word[i]) in ['A'..'Z']) then
            correctname:= false;        
end;

function Cryptname(var word : String): String;
var 
    wordcrypt: String;

begin
    wordcrypt:= '';
    str(length(word) - 2, wordcrypt);
    Cryptname:= word[1] + wordcrypt + word[length(word)];
end;        

begin
    repeat
        repeat
            readln(word);
        until correctname(word);

        if correctname(word) and (length(word) > 10) then   
            writeln(Cryptname(word))
            //writeln(word);
        else
            writeln(word);
        //readkey();
    until false;        
end.
**更新:**

program A71;
uses wincrt;
type
    tab = array[1..100] of String;
var
    word: tab;
    correctwords,n, i : Integer;

function correctname(word : tab; correctwords : Integer): Boolean;
var
    i : Integer;
begin
    correctname:= true;
    i:= 0;
    //for i:=1 to length(word[correctwords]) do 
    repeat 
        i:=i+1;
        if not (upcase(word[correctwords][i]) in ['A'..'Z']) then
            correctname:= false;
    until not correctname or (i = length(word[correctwords]));          
end;

procedure Cryptname(var word : tab; correctwords : Integer);
var 
    wordcrypt: String;

begin
    //wordcrypt:= '';
    str(length(word[correctwords]) - 2, wordcrypt);
    word[correctwords]:= word[correctwords][1] + wordcrypt + word[correctwords][length(word)];
end;        

begin
    correctwords:=0;
    readln(n);
    repeat
        readln(word[correctwords]);
        if correctname(word, correctwords) then
            correctwords:= correctwords+1;
    until correctwords = n;

    for i:= 1 to correctwords do
    begin
            if correctname(word, correctwords) and (length(word[correctwords]) > 10) then
            begin
                Cryptname(word, correctwords);
                writeln(word[correctwords]);
            end 
        else    
            writeln(word[correctwords]);
    end;
    readkey();      
end.
现在,我的代码在第二次输入时直接崩溃

更新,我用这种方式解决了它:

program A71;
uses wincrt;
type
    tab = array[1..100] of String;
var
    word: tab;
    correctwords,n, i : Integer;
    tester : String;

function correctname(tester : String): Boolean;
var
    i : Integer;
begin
    correctname:= true;
    i:= 0;
    //for i:=1 to length(word[correctwords]) do 
    repeat 
        i:=i+1;
        if not (upcase(tester[i]) in ['A'..'Z']) then
            correctname:= false;
    until not correctname or (i = length(tester));          
end;

procedure Cryptname(var wordcrypt : String);
var
    wordcryptaux: String;
begin
    wordcryptaux:= wordcrypt;
    str(length(wordcrypt) - 2, wordcrypt);
    wordcrypt:= wordcryptaux[1] + wordcrypt + wordcryptaux[length(wordcryptaux)];
end;        

begin
    correctwords:=0;
    readln(n);
    repeat
        
        readln(tester);
        if correctname(tester) then
            correctwords:= correctwords+1;
            word[correctwords]:= tester;
    until correctwords = n;

    for i:= 1 to correctwords do
    begin
        if correctname(word[i]) and (length(word[i]) > 10) then
            begin
                Cryptname(word[i]);
                writeln(word[i]);
            end 
        else    
            writeln(word[i]);
    end;
    readkey();      
end.

多谢各位

我对你的代码做了一点修改和改进。如果主程序中的只有一行,但缩进使您认为它有两行,请注意您的
;我也解决了这个问题

program A71;
uses wincrt;
type
    tab = array[1..100] of String;
var
    word: tab;
    correctwords, n, i: Integer;
    tester: String;

function correctname(inputword : String): Boolean;
var
    i: Integer;
begin
    for i:=1 to length(inputword[correctwords]) do
    begin
        if not (upcase(inputword[i]) in ['A'..'Z']) then
            Exit(false);
    end;
    Exit(true);
end;

procedure Cryptname(var wordcrypt : String);
var
    wordcryptaux: String;
begin
    wordcryptaux:= wordcrypt;
    str(length(wordcrypt) - 2, wordcrypt);
    wordcrypt := wordcryptaux[1] + wordcrypt + wordcryptaux[length(wordcryptaux)];
end;

begin
    correctwords:=0;
    readln(n);
    repeat
        readln(tester);
        if correctname(tester) then begin
            Inc(correctwords);
            word[correctwords]:= tester;
        end;
    until correctwords = n;

    for i:=1 to correctwords do
    begin
        if correctname(word[i]) and (length(word[i]) > 10) then
            Cryptname(word[i]);
        writeln(word[i]);
    end;
    readkey();
end.

我不知道你在问什么。您是否希望能够按几次(4)直到“完成”为止?程序如何知道您已完成?总是4行吗?也许结尾有一个空行?顺便说一句,
correctname
总是检查单词,直到不必要的结尾。一旦它是假的,你就应该打破循环。是
wordcrypt:=''必需?第一个输入是行数。因此它取决于输入,我将尝试使指令在数组中工作,并提出一个更新。是的,wordcrypt必须初始化,因为如果我没有初始化,就会收到警告。研究如何打开编译器的范围检查。在崩溃行的前面打印变量,然后运行它again@MarcovandeVoort我已经用一个简单的for循环和一个数组解决了这个问题(你可以在上面看到),但是你能解释一下范围检查吗?我使用升华编译器和一个来自谷歌的简单FPC包。谢谢你们两位度过的美好时光,我不知道如何给你们一个名誉点,请原谅。