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
#include
#include
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< temp_x=temp_x-ww;
if(temp_x==0)
break;
}
cout<<"Problem set "< for(k=b;k<=e;k++)
cout< cout<
memset(a,0,sizeof(int)*300);
}
system("pause");
return 0;
}
额,这是我的运行结果,正确的应该是Problem set 4:511 / 977,base 7 digits 122 through 126:12425