ACM题出错了,不知道错误在哪里, Consecutive DigitsInput: Theinput file begins with a line containing a single integer specifyingthe number of problem sets in the file.Each problem set is specifiedby four base 10 numbers on a single line,n

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/07 02:08:30
ACM题出错了,不知道错误在哪里,  Consecutive DigitsInput: Theinput file begins with a line containing a single integer specifyingthe number of problem sets in the file.Each problem set is specifiedby four base 10 numbers on a single line,n

ACM题出错了,不知道错误在哪里, Consecutive DigitsInput: Theinput file begins with a line containing a single integer specifyingthe number of problem sets in the file.Each problem set is specifiedby four base 10 numbers on a single line,n
ACM题出错了,不知道错误在哪里,
  Consecutive Digits



Input: The
input file begins with a line containing a single integer specifying
the number of problem sets in the file.Each problem set is specified
by four base 10 numbers on a single line,n d b e,where n
and d are the numerator and denominator of the rational number
and 0 ≤ n ≤ 5,000 and 1 ≤ d ≤ 5,000.b and e are the beginning and ending
positions for the desired range of digits,with 0 ≤ b,e ≤ 250 and
0 ≤ (e-b) ≤ 20.Note that 0 is
the position immediately to the right of the decimal point.
Output: Each
problem set will be numbered (beginning at one) and will generate a
single line:
Problem set k:n / d,
       base 7 digits b through e:result
where k is replaced by the problem set number,result is
your computed result,and the other values are the corresponding input
values.
 Example input:   
   Example output:     

    4
1 5 0 0
6 49 1 3
33 4 2 7

511 977 122 126
Problem set 1:1
/ 5,base 7 digits 0 through 0:1
Problem set 2:6 / 49,base 7 digits 1 through 3:600
Problem set 3:33 / 4,base 7 digits 2 through 7:151515
Problem set 4:511 / 977,base 7 digits 122 through 126:12425



我的代码:
#include<iostream>
#include<string.h>
#include<memory.h>
using namespace std;
int main()
{
    int casenum,b,e,i,j,k,temp_z,ww,a[300]={0},size;
    float n,d,temp_x;
  cin>>casenum;
    for(i=1;i<=casenum;i++)
    {
            cin>>n>>d>>b>>e;
            
            temp_z=int(n/d);
            temp_x=n/d;
            temp_x=float(temp_x-temp_z);                  
            for(j=0;j<300;j++)
            {
            temp_x=temp_x*7;
            ww=int(temp_x);
            a[j]=ww;
            //cout<<a[j]<<" ";           
            temp_x=temp_x-ww;
            if(temp_x==0)
            break;
            }        
            cout<<"Problem set "<<i<<":"<<n<<" / "<<d<<",base 7 digits "<<b<<" through "<<e<<":";
            for(k=b;k<=e;k++)
            cout<<a[k];
            cout<<endl;
            
           memset(a,0,sizeof(int)*300);
            
     }  
     system("pause");
     return 0;
}
                

额,这是我的运行结果,正确的应该是Problem set 4:511 / 977,base 7 digits 122 through 126:12425

ACM题出错了,不知道错误在哪里, Consecutive DigitsInput: Theinput file begins with a line containing a single integer specifyingthe number of problem sets in the file.Each problem set is specifiedby four base 10 numbers on a single line,n
十进制小数转七进制. 小数部分,确定是乘以7然后再取整数部分.
但是这个方法前提是这个小数是有限小数.虽然对于一些无限小数,可以得到正确解,但是随着所求位置越大,你的误差也越大.
而且你这里用了float类型,这里也有一个精度损失.
这道题也不是很难.
对于 d/n 先拿掉他的整数部分. 变成d
d0/n ==> d0*7/n 这里取整数,也去掉整数成d1/n . 这里就是第0位.
d1/n ==> d1*7/n .除整数,成d2/n .这里就是第1位.
.
这样精度就不会丢失. 方法跟你类似.但是保持分母不变. 每次除整,保证精度不损失 .
还有一点,可以不用那个数组. 用个循环.
for(i=0;i

ACM题出错了,不知道错误在哪里, Consecutive DigitsInput: Theinput file begins with a line containing a single integer specifyingthe number of problem sets in the file.Each problem set is specifiedby four base 10 numbers on a single line,n 三角函数求周期.我不知道哪里出错了,急,求指出错误及思考方向 初三一道数学题,我做错了,做的过程在,高手看一下我在哪一步出错如题,我实在是不知道错在哪里,苦想了很久啊 C语言一道题目.不知道哪里出错了,#includeint main(){int b[3][4];int i,j,max,m,n;for(i=0;i matlab程序出现了错误,不知道哪里出错了这样的程序clearsyms a b ;c=[a b]';A=[2.9 3.6 4.5 5.88 8.1];B=cumsum(A);n=length(A);for i=1:(n-1)c(i)=(B(i)+B(i+1))/2;endD=A;D(1)=[];D=D';E=[-C;ones(1,n-1)];c=inv(E*E')*E*D;c=c&# 第六题我哪里出错了数学题 错别字哪里出错了? C语言问题,告诉半径和高,求球体体积,圆柱体体积,圆锥体体积.我在告诉已知量PI的时候出错了.我应该把它放在哪里?还有我整体的格式有错误么?.. Multisim10仿真时提示错误 求知道,用桥式整流电源就出错,直接接+12就可以运行,求解哪里错了啊,该怎么改正? 自制电动机为什么不转动?哪里出错了? 拉式变换求解微分方程.2c'+c=3 初始条件为0,我算出的答案是Z(t)+36(t) 跟答案不一样,不知道哪里出错了. ACM的题,不知道错在哪里了.某日,小Y同学迷恋上一女生,于是决定向该女生表白。可是,悲剧往往发生在帅哥身上。在小Y同学表白后,该女生发来一短信,该短信由一行字符串组成。并告知 一质点由静止开始做匀加速直线运动,若该质点在第n秒内的位移是x,那么它的加速度大小为( )A.2n / xB.x / (n-1)C.2x / (2n-1)D.x / (2n-1)我算出来的答案在这四个选项里都没有不知道哪里出错了x 也 c语言acm题 写道高数题错在哪里了.如题,绞尽脑汁就是不知道哪里错了. matlab矩阵相乘问题,到底哪里出错了?如下图,左边错误提示,右边源代码. sumif 公式错误老是说A列出错,不知道是什么原因 超幼稚问题关于冠词不知道哪里错了今天看到一道初中题目是It's__ useful book.选项有A.a B.an C.the D./我毫不犹豫选了B 以为useful是元音开头的单词 结果一看答案居然是A 郁闷 不知道哪里出错了(