There can be some problem in ur printf().
The actual data types for a[n].x and a[n].y were long double and long int respectively. But u used %f and %d in the printf().printf("2^-%ld = %1.3fe-%d\n",n,a[n].x,a[n].y);
Moderator: Board moderators
Code: Select all
11
12
13
23
24
25
7
6
47
48
49
1000000
Code: Select all
2^-11 = 4.883e-4
2^-12 = 2.441e-4
2^-13 = 1.221e-4
2^-23 = 1.192e-7
2^-24 = 5.960e-8
2^-25 = 2.980e-8
2^-7 = 7.813e-3
2^-6 = 1.563e-2
2^-47 = 7.105e-15
2^-48 = 3.553e-15
2^-49 = 1.776e-15
2^-1000000 = 1.010e-301030
Code: Select all
cin>>n;
cout<<"2^"<<n<<" = ";
tmp=log10((double)2)*(n);
b=floor(tmp);
a=pow((double)10,tmp-b);
cout<<a<<'e'<<b<<endl;
Code: Select all
//474 Heads / Tails Probability
///////////////////////////////
//same as 545
///////////////////////////////
#include <iostream>
#include <cmath>
using namespace std;
int main(int argc,char *argv[])
{
long n;
double a,tmp;
long b;
cout.setf(ios::fixed,ios::floatfield);
cout.precision(3);
while(cin>>n)
{
n=-n;
cout<<"2^"<<n<<" = ";
tmp=log10((double)2)*(n);
b=floor(tmp);
a=pow((double)10,tmp-b);
cout<<a<<'e'<<b<<endl;
}
}
Code: Select all
athena_kula@msn.com
This is crazy! I've got 10 WA's before I read your post.. and I added the exception case for (n = 6, which i strongly believe the correct answer to be 1.563e-2) and got AC!!! Thanks to your post again...Now the funny part is that I checked all possibilities and got the same result, except for n = 6.
My solution gave first 2^-6 = 1.563e-2 and got a WA.
Now it returns 2^-6 = 1.562e-2 and it gets accepted. In my opinion this is a wrong answer (1.5625 should round up to 1.563).