usaco 2.4 fracdec 2008.6.30

usaco 2.4 fracdec 2008.6.30

{

1.刚开始用商来作标识,不是一个好方法,后来用余数作标识。

2.结果可能有很多位,记录结果的,不能用string,而应开一个数组

3.多试几组数据,否则只能过一两组

4.要先检查一下自己的程序无误,确保正确,再试数据,否则,只有一两个简单数据对了,是不能得满分的!}

{

ID:  

PROG: fracdec

LANG: PASCAL

}

program p_fracdec;
const maxn=100000;fin='fracdec.in';fout='fracdec.out';
var f1,f2:text;
     f:array[0..maxn]of boolean;
     b:array[1..maxn]of longint;
     a,h:array[1..maxn]of char;
     p,s:string;flag:boolean;
     lh,lp,n,d,i,j,x,l,r,lb,t,y,ls:longint;
begin
  assign(f1,fin);reset(f1);assign(f2,fout);rewrite(f2);
  read(f1,n,d);fillchar(f,sizeof(f),false);
  str(n div d,s);flag:=false;ls:=length(s);
  for i:=1 to ls do a[i]:=s[i];l:=ls+1;a[l]:='.';
  x:=n mod d;
   ifx=0 then begin inc(l);a[l]:='0';h:=a;lh:=l;end
else
 begin
  f[x]:=true;lb:=1;b[1]:=x;
  repeat
     x:=x*10;str(x div d,p);lp:=length(p);
     for i:=1 to lp do begin inc(l);a[l]:=p[i];end;
     x:=x mod d;inc(lb);b[lb]:=x;
     if f[x] then begin flag:=true end else f[x]:=true;
  until flag;
  i:=0;repeat inc(i);until b[i]=x;
  t:=ls+1;y:=t+i-1;lh:=0; writeln(a[t]);
   ifx<>0 then
    begin
      for i:=1 to y do begin inc(lh);h[lh]:=a[i];end;
      inc(lh);h[lh]:='(';
      for i:=y+1 to lb+t-1 do begin inc(lh);h[lh]:=a[i];end;
      inc(lh);h[lh]:=')';
     end
      else for i:=1 to y do begin inc(lh);h[lh]:=a[i];end;
 end;
  for i:=1 to lh do if i mod 76=0 then writeln(f2,h[i]) elsewrite(f2,h[i]);writeln(f2);
  close(f1);close(f2);
  end.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值