Trinary NumberTime Limit:1000MS Description Maybe you want to ask "What is the trinary numbers?" For example,Binary is based on two,while the decimal number is based on ten,so the trinary number is based on three.For example,the decimal number 3 is 1
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/19 05:23:33
Trinary NumberTime Limit:1000MS Description Maybe you want to ask "What is the trinary numbers?" For example,Binary is based on two,while the decimal number is based on ten,so the trinary number is based on three.For example,the decimal number 3 is 1
Trinary Number
Time Limit:1000MS
Description
Maybe you want to ask "What is the trinary numbers?" For example,Binary is based on two,while the decimal number is based on ten,so the trinary number is based on three.For example,the decimal number 3 is 10 in trinary form.Your task,it is to transform a fraction which be presented in the form 'x/y' and the value is limited in 0 to 1 into trinary form.
Input
The first line of the input contains a single integer T (0 < T < 1000),indicating the number of test cases.
For each test case,there is a fraction pre line,each consist of numerator and denominator which separated by a slash without any blanks.(0 < x < y < 100)
Output
For each test case,print a transformed fraction from decimal to trinary form beginning with a point per line.
Sample Input
4
1/3
1/4
1/6
7/8
Sample Output
.1000000000
.0202020202
.0111111111
.2121212121
我的代码:
#include
#include
int main()
{
int i,t,x,y;
int c[10],sign=0;
double a=0;
char ch;
scanf("%d",&t);
while(t--)
{
scanf("%d",&x);
scanf("%c",&ch);
scanf("%d",&y);
a=(double)x/(double)y;
printf(".");
for(i=0;i
Trinary NumberTime Limit:1000MS Description Maybe you want to ask "What is the trinary numbers?" For example,Binary is based on two,while the decimal number is based on ten,so the trinary number is based on three.For example,the decimal number 3 is 1
你试一下不要把x/y,直接3*x/y,取整输出,你的程序应该是a=(double)x/(double)y;的算法有点问题吧 ,还有一点x/y==1的时候正确答案是.3000000000;
仅供参考:
#include
int main()
{
int i,t,x,y;
int c[10],sign=0;
double a=0;
char ch;
scanf("%d",&t);
getchar();
while(t--)
{
scanf("%d",&x);
scanf("%c",&ch);
scanf("%d",&y);
a=(double)x/(double)y;
printf(".");
for(i=0;i