div:last-child {padding-bottom: 0;border: none;}.mass_comments_action {display: none;}.comm-box {margin-bottom: 20px;}.comm-title {float: left;font-size: 22px;font-weight: 700;color: #333;}.full-title {font-size: 22px;font-weight: 700;color: #333;margin-bottom: 20px;}.comm-user {float: right;font-size: 14px;padding-top: 5px;}.comm-bott {font-size: 17px;line-height: 24px;}.comm-bott > div, .answers .element .content {word-wrap: break-word;font-size: 18px;line-height: 24px;font-weight: 400;color: #000;}#news_set_sort {float: right;margin-top: -5px;}.side-title {color: #333;font-weight: 800;text-align: center;margin-bottom: 15px;}.side-btnbox {text-align: center;}.btn.bg-blue {background-color: #4fb3f6;}#moreres {background: #fff;color: #000;font-size: 14px;text-transform: none;box-shadow: none;border-radius: 17px;border-bottom: 2px solid #e9e9e9;}#moreres.lds-ring-loader {opacity: 0.5;cursor: default;}#moreres .lds-ring {display: inline-block;position: absolute;width: 35px;height: 35px;}#moreres .lds-ring div {box-sizing: border-box;display: block;position: absolute;width: 30px;height: 30px;margin: 3px;border: 3px solid #333;border-radius: 50%;animation: lds-ring 1.2s cubic-bezier(0.5, 0, 0.5, 1) infinite;border-color: #333 transparent transparent transparent;}#moreres .lds-ring div:nth-child(1) {animation-delay: -0.45s;}#moreres .lds-ring div:nth-child(2) {animation-delay: -0.3s;}#moreres .lds-ring div:nth-child(3) {animation-delay: -0.15s;}@keyframes lds-ring {0% {transform: rotate(0deg);}100% {transform: rotate(360deg);}}
profile
Опубликовано 6 лет назад по предмету Информатика от Sayu

В чем ошибка? Пишет "Индекс находится вне границ массива" вроде 17 сторока
program test;
uses crt;
var s, s1:string;
n, f, i, j, len:integer;
begin 
   clrscr; 
   writeln('введите предложение'); 
    readln(s); 
    s:=' '+s; 
    writeln('ведите приставку'); 
    readln(s1); 
    len:=length(s1); 
    n:=0; 
    f:=0;  while j<=length(s) do   
             begin   
                  if s[j]=' ' then                      
                                    begin
                                            for i:=1 to len do
                                             if s[j+i]<>s1[i] then f:=1;
                                                                       if f=0 then begin                                                                                                                                      n:=n+1;                                                                                                                            j:=j+len;                                                                                                                      end                                  
                                                                                else j:=j+1;                                                  end;   
   end; 
writeln('n=',n); 
readln; 
end.

В выделенной строке выдает ошибку

  1. Ответ
    Ответ дан Kiyanitsinaaaa
    задание не много не понятно, где что стоит, лучше сфотай
  2. Ответ
    Ответ дан emblerik
    Смотрите, в этом цикле:
    while j<=length(s) do   
    J может быть равно длине строки. А внутри цикла есть вот это:
      if s[j+i]<>s1[i] then f:=1;
    То есть если s[J] - последний символ, то на этой строчке пойдет обращение уже к несуществующему индексу массива.
    1. Ответ
      Ответ дан emblerik
      надо опустить else j := j + 1 На строчку ниже
    2. Ответ
      Ответ дан Sayu
      благодарю
    3. Ответ
      Ответ дан emblerik
      и else убрать - там же в любом случае надо увеличить
    4. Ответ
      Ответ дан emblerik
      f := 0 внести в цикл while и вроде работает
    5. Ответ
      Ответ дан Sayu
      спасибо огромное, все работает х)
Самые новые вопросы