回 帖 发 新 帖 刷新版面

主题:tju1127

program tju1127;
var a:array[1..100] of integer;
    b,c:integer;
begin
while not seekeof(input) do
  begin
   fillchar(a,sizeof(a),0);
   readln(b);
   for c:=1 to b do
     readln(a[c]);
   for c:=1 to b do
    begin
     write(a[c],' ');
     while a[c]<>1 do
      begin
       if odd(a[c])
        then a[c]:=a[c]*3+1
        else a[c]:=a[c] div 2;
       write(a[c],' ');
      end;
     writeln;
    end;
   end;
end.

非法数字格式~~~~~~~~~~~~~~

回复列表 (共1个回复)

沙发

[em2]
program tju1127;
var
  n,i,j:byte;
  s:string;
begin
  readln(n);
  for i:=1 to n do begin
    readln(s);
    while s<>'1' do begin
      write(s,' ');
      if odd(ord(s[length(s)])) then begin
        for j:=1 to length(s) do
          s[j]:=chr(48+(ord(s[j])-48)*3);
        inc(s[length(s)]);s:='0'+s;
        for j:=length(s) downto 2 do begin
          inc(s[j-1],(ord(s[j])-48) div 10);
          s[j]:=chr(48+(ord(s[j])-48) mod 10);
        end;
      end
      else
        for j:=1 to length(s) do begin
          if odd(ord(s[j])) then inc(s[j+1],10);
          s[j]:=chr(48+(ord(s[j])-48) shr 1);
        end;
      if s[1]='0' then delete(s,1,1);
    end;
    writeln('1 ');
  end;
end.

我来回复

您尚未登录,请登录后再回复。点此登录或注册