博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Octal Fractions
阅读量:4575 次
发布时间:2019-06-08

本文共 3116 字,大约阅读时间需要 10 分钟。

 

                                                   Octal Fractions

                                Time Limit: 1 Sec  Memory Limit: 64 MB

Submit: 149  Solved: 98

Description

Fractions in octal (base 8) notation can be expressed exactly in decimal notation. For example, 0.75 in octal is 0.963125 (7/8 + 5/64) in decimal. All octal numbers of n digits to the right of the octal point can be expressed in no more than 3n decimal digits to the right of the decimal point.

Input

Write a program to convert octal numerals between 0 and 1, inclusive, into equivalent decimal numerals. The input to your program will consist of octal numbers, one per line,to be converted. Each input number has the form 0.d1d2d3 ... dk, where the di are octal digits (0..7). There is no limit on k.

Output

Your output will consist of a sequence of lines of the form 0.d1d2d3 ... dk [8] = 0.D1D2D3 ... Dm [10] where the left side is the input (in octal), and the right hand side the decimal (base 10) equivalent. There must be no trailing zeros, i.e. Dm is not equal to 0.

Sample Input

0.750.00010.01234567

Sample Output

0.75 [8] = 0.953125 [10]0.0001 [8] = 0.000244140625 [10]0.01234567 [8] = 0.020408093929290771484375 [10] 因为大数除法是顺的方便,加法是逆的方便,让我纠结了好久=_=,最后觉定都顺吧,就AC了
1 #include
2 #include
3 #include
4 void divi(int p[],int x,int *len) 5 { 6 int temp=0,i,j; 7 for(i=0;i<*len+3;i++) 8 { 9 temp=temp*10+p[i]; 10 p[i]=temp/x; 11 temp%=x; 12 } 13 14 for(i=*len+3;i>=0;i--) 15 { 16 if(p[i]) 17 { 18 *len=i+1; 19 break; 20 } 21 } 22 23 /* for(i=0;i<*len;i++) 24 printf("p[%d]=%d\n",i,p[i]); 25 printf("\n"); */ 26 } 27 28 void add(int p1[],int p2[],int *len1,int *len2) 29 { 30 int lst,i,j; 31 int co_p1[200]; 32 33 memset(co_p1,0,sizeof(co_p1)); 34 lst=*len1>=*len2?*len1:*len2; 35 36 for(i=0,j=lst-1;i
9) 40 { 41 co_p1[i]-=10; 42 co_p1[i+1]++; 43 } 44 } 45 *len2=lst; 46 if(p1[i]) 47 *len2++; 48 49 for(i=0,j=*len2-1;i<*len2;i++,j--) 50 p1[i]=co_p1[j]; 51 /* printf("和:"); 52 for(i=0;i<*len2;i++) 53 printf("%d",p1[i]); 54 printf("\n\n");*/ 55 } 56 57 int main() 58 { 59 //freopen("a.txt","r",stdin); 60 int i,j,k; 61 int len; //放应保留的位数 62 int len1,len2; //len1为每个商的长度,len2 63 int num_a[200];//放商 64 int num_sum[200];//放商的和 65 char str[201]; 66 67 while(gets(str)!=NULL) 68 { 69 printf("%s [8] = 0.",str); 70 len=strlen(str); 71 len=(len-2)*3; 72 len2=len1=1; 73 74 memset(num_sum,0,sizeof(num_sum)); 75 76 for(i=2;str[i]!='\0';i++) 77 { 78 len1=1; 79 memset(num_a,0,sizeof(num_a)); 80 num_a[0]=str[i]-'0'; 81 if(!num_a[0]) 82 { 83 continue; 84 } 85 else 86 { 87 for(j=0;j
View Code

 

 

转载于:https://www.cnblogs.com/get-an-AC-everyday/p/4174342.html

你可能感兴趣的文章
spring源码学习——spring整体架构和设计理念
查看>>
模拟window系统的“回收站”
查看>>
报文格式【定长报文】
查看>>
RDLC报表钻取空白页问题
查看>>
多路电梯调度的思想
查看>>
jQuery-对Select的操作
查看>>
过滤器、监听器、拦截器的区别
查看>>
为什么要进行需求分析?通常对软件系统有哪些需求?
查看>>
一些模板
查看>>
jquery和dom元素相互转换
查看>>
放大的X--HDOJ-201307292012
查看>>
题目831-签到-nyoj-20140818
查看>>
百词斩-斩家秘籍
查看>>
Mysql主从配置,实现读写分离
查看>>
真事儿!——我们官网被全站拷贝了!
查看>>
抽象类及抽象方法
查看>>
Canvas基本绘画学习
查看>>
Django ORM 最后操作
查看>>
HDU 1050(贪心)
查看>>
java设计模式之代理模式
查看>>