USACO 2.4 Fractions to Decimals

郁闷,没看见76个字符换行啊。。。。一直错。。。。然后看着数据,添各种坑,终于让这搓代码过了。。。磕磕绊绊终于结束第二章了!!!上图。

USACO 2.4 Fractions to Decimals

总体上来说,是乱搞题目,模拟之类居多,比我想像的刷的快啊。

 1 /*

 2   ID: cuizhe

 3   LANG: C++

 4   TASK: fracdec

 5 */

 6 #include <iostream>

 7 #include <cstdio>

 8 #include <cstring>

 9 #include <cmath>

10 #include <algorithm>

11 using namespace std;

12 int o[1000001];

13 int que[1000001];

14 int main()

15 {

16     int n,d,z,i,ans2,ans1,num,line = 1;

17     freopen("fracdec.in","r",stdin);

18     freopen("fracdec.out","w",stdout);

19     scanf("%d%d",&n,&d);

20     ans1 = n/d;

21     if(n%d == 0)

22     {

23         printf("%d.0\n",ans1);

24         return 0;

25     }

26     ans2 = n%d;

27     num = 1;

28     z = 0;

29     while(ans2 != 0)

30     {

31         ans2 = ans2*10;

32         if(!o[ans2])

33         {

34             que[num] = ans2/d;

35             o[ans2] = num;

36         }

37         else

38         {

39             z = o[ans2];

40             break;

41         }

42         num ++;

43         ans2 = ans2%d;

44         if(z) break;

45     }

46     printf("%d.",ans1);

47     if(ans1 == 0) line++;

48     while(ans1)

49     {

50         ans1 = ans1/10;

51         line ++;

52     }

53     if(z)

54     {

55         for(i = 1;i <= num-1;i ++)

56         {

57             if(line%76 == 0)

58             printf("\n");

59             if(i == z)

60             {

61                 printf("(");

62                 line ++;

63             }

64             printf("%d",que[i]);

65             line ++;

66         }

67         printf(")\n");

68     }

69     else

70     {

71         for(i = 1;i <= num-1;i ++)

72         {

73             if(line%76 == 0)

74             printf("\n");

75             printf("%d",que[i]);

76             line ++;

77         }

78         printf("\n");

79     }

80     return 0;

81 }

 

你可能感兴趣的:(action)