thieumao

Đảo bit

May 27th, 2013
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.77 KB | None | 0 0
  1. program GiaiMa;
  2. uses crt;
  3. type mang=array[1..20] of string;
  4. var
  5.   F,F2: Text;
  6.   path,path2,temp: string;
  7.   s: mang;
  8.   ch:char;
  9.   i,j,lech:byte;
  10. {*****DAO NGUOC CHUOI*****}
  11. function nguoc(str: string):string;
  12. var
  13.   i:byte;
  14. begin
  15.   nguoc:='';
  16.   for i:=length(str) downto 1  do nguoc:=nguoc+str[i];
  17. end;
  18. {*****QUAY VONG *****}
  19. function vong(str: string; v:byte):string;
  20. var i,so:byte;
  21. begin
  22.   vong:='';
  23.   for i:=1 to length(str) do
  24.     begin
  25.       so:=ord(str[i]);
  26.       if (so>=65) and (so<=90) then
  27.         begin
  28.           so:=(so-65-v+26) mod 26 + 65;
  29.           vong:=vong+chr(so+32);
  30.         end
  31.       else
  32.         begin
  33.           vong:=vong+chr(so);
  34.         end;
  35.     end;
  36. end;
  37. {***** DOI BIT *****}
  38. function doibit(str: string):string;
  39. var i:byte;
  40. begin
  41.   doibit:='';
  42.   for i:=1 to length(str) do
  43.     begin
  44.       if (str[i]='0') then
  45.         doibit:=doibit+'1'
  46.       else
  47.         begin
  48.           if (str[i]='1')
  49.             then doibit:=doibit+'0'
  50.           else
  51.             doibit:=doibit+str[i];
  52.         end;
  53.     end;
  54. end;
  55. {***** CHUONG TRINH CHINH *****}
  56. begin
  57.   clrscr;
  58.   {write('Nhap path file: ');='mao.txt';
  59.   readln(path);}
  60.   path:='/home/thieumao/Desktop/input.txt';
  61.   assign(F, path);
  62.   reset(F);
  63.   i:=0;
  64.   writeln('***FILE INPUT***');
  65.   while (not eof(f)) do
  66.     begin
  67.       while (not eoln(F)) do
  68.         begin
  69.           i:=i+1;
  70.           readln(F,s[i]); writeln('Dong ',i:2,': ',s[i]);
  71.         end;
  72.       {readln(F); writeln;}
  73.     end;
  74.   close(F);
  75.   writeln;
  76.  
  77.   writeln('***FILE OUTPUT***');
  78.   path2:='/home/thieumao/Desktop/output.txt';
  79.   assign(F2, path2);
  80.   rewrite(F2);
  81.  
  82.   for j:=1 to i do
  83.     begin
  84.       writeln(F2, doibit(s[j]));
  85.       writeln('Dong',j:2,': ', doibit(s[j]) );
  86.     end;
  87.   close(F2);
  88. end.
Advertisement
Add Comment
Please, Sign In to add comment