早教吧作业答案频道 -->其他-->
TrinaryNumberTimeLimit:1000MSDescriptionMaybeyouwanttoask"Whatisthetrinarynumbers?"Forexample,Binaryisbasedontwo,whilethedecimalnumberisbasedonten,sothetrinarynumberisbasedonthree.Forexample,thedecimalnumber3is1
题目详情
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
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
▼优质解答
答案和解析
你试一下不要把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
仅供参考:
#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
看了 TrinaryNumberT...的网友还看了以下:
TakeBeijingforexample,itisoneoftheoldestcitiesint 2020-05-17 …
TrinaryNumberTimeLimit:1000MSDescriptionMaybeyouw 2020-05-19 …
英语短文中单词使用原因解释forexample,you1(arewatching)yourfavo 2020-05-22 …
请解释一个英语句子(看似简单,但许多人解释的一塌糊涂)---高手帮忙Inourschool,the 2020-05-23 …
八年级新目标第二单元SectionB3a里的“Forexample,areyouoftenweak 2020-06-06 …
Forexample,areyouoftenweakandtired?这句话中的Forexampl 2020-06-06 …
请老师帮忙分析一下句子结构Thegovernmenthasreducedspendinginsev 2020-06-08 …
forexample,是不是只能举一个例子,不能多举吗那课本中有,forexample,idont 2020-06-12 …
用suchas/forexample/thatis/andsoon适当形式填空suchas/for 2020-07-09 …
suchas可以在句首吗Suchastrain,busandcar.Therearemanymea 2020-08-04 …