Размещено 3 года назад по предмету
Информатика
от Minerva00100
Сделать перевод из Паскаль в С++ Помогите пожалуйста! Вот код: uses CRT; const min_hash=ord('0')+ord('0'); max_hash=ord('z')+ord('z'); ind_sym=['a'..'z','A'..'Z','0'..'9','_']; type max_string=string[32]; pInd_elem=^ind_elem; ind_elem=record data:max_string; next:pInd_elem; end; hash_table=array[min_hash..max_hash] of pInd_elem; var ht:hash_table; fd:file of char; i,cur_elem,all_col_count,check_count,count:integer; ind_str:max_string; ch:char; FileName:string; rez:LongInt; procedure CreateHash; begin cur_elem:=ord(ind_str[1])+ord(ind_str[length(ind_str)]); end; procedure FindInd(var t:pInd_elem); begin inc(check_count); if t<>nil then begin if t^.data=ind_str then begin WriteLn(cur_elem:5,#9,t^.data); WriteLn(' Число сравнений ',check_count); end else FindInd(t^.next); end else WriteLn(' Идентификатор не найден'); end; procedure GetIndName; begin write(' Введите нужный идентификатор: '); ReadLn(ind_str); end; procedure colliz(var t:pInd_elem); begin if t=nil then begin t:=new(pInd_elem); t^.data:=ind_str; t^.next:=nil; inc(count); inc(all_col_count); end else if t^.data<>ind_str then colliz(t^.next); end; procedure GetHash; begin CreateHash; if ht[cur_elem]=nil then begin ht[cur_elem]:=new(pInd_elem); ht[cur_elem]^.data:=ind_str; ht[cur_elem]^.next:=nil; inc(count); end else if ht[cur_elem]^.data<>ind_str then colliz(ht[cur_elem]^.next); end; begin ClrScr; write('Введите имя файла с идентификаторами: '); ReadLn(FileName); for i:=min_hash to max_hash do ht[i]:=nil; {$I-} assign(fd,FileName); reset(fd); rez:=IOResult; {$I+} if rez=0 then begin WriteLn('Строим таблицу идентификаторов '); count:=0; all_col_count:=0; ind_str:=''; while(not EOF(fd)) do begin read(fd,ch); while(ch in ind_sym)do begin ind_str:=ind_str+ch; read(fd,ch); end; if ind_str<>'' then begin GetHash; ind_str:=''; end; end; close(fd); WriteLn('Таблица построена'); WriteLn(' Было найдено ',count,' идентификаторов '); WriteLn(' Было обнаружено ',all_col_count,'коллизии'); ch:='0'; repeat if UpCase(ch)='Y' then begin check_count:=0; GetIndName; CreateHash; FindInd(ht[cur_elem]); end; write('Искать идентификатор y/n: '); ReadLn(ch); until UpCase(ch)='N'; end else WriteLn(' Невозможно открыть файл ',FileName); end.