想請教一下,為什麼這樣到第十個測資會錯??
謝謝!!
#include<iostream>
using namespace std;
int main()
{
long long n,m;
long long digit;
while(cin >> n >> m)
{
if(n == 1)
cout << 1 << endl;
else if(n == 10)
cout << m+1 << endl;
else if(n == 2)
{
digit=0.3010*m+1;
cout << digit << endl;
}
else if(n == 3)
{
digit=0.4471*m+1;
cout << digit << endl;
}
else if(n == 4)
{
digit=0.6020*m+1;
cout << digit << endl;
}
else if(n == 5)
{
digit=0.6990*m+1;
cout << digit << endl;
}
else if(n == 6)
{
digit=0.7781*m+1;
cout << digit << endl;
}
else if(n == 7)
{
digit=0.8451*m+1;
cout << digit << endl;
}
else if(n == 8)
{
digit=0.9030*m+1;
cout << digit << endl;
}
else
{
digit=0.9542*m+1;
cout << digit << endl;
}
}
return 0;
}
想請教一下,為什麼這樣到第十個測資會錯??
謝謝!!
#include
using namespace std;
int main()
{
long long n,m;
long long digit;
while(cin >> n >> m)
{
if(n == 1)
cout << 1 << endl;
else if(n == 10)
cout << m+1 << endl;
else if(n == 2)
{
digit=0.3010*m+1;
cout << digit << endl;
}
else if(n == 3)
{
digit=0.4471*m+1;
cout << digit << endl;
}
else if(n == 4)
{
digit=0.6020*m+1;
cout << digit << endl;
}
else if(n == 5)
{
digit=0.6990*m+1;
cout << digit << endl;
}
else if(n == 6)
{
digit=0.7781*m+1;
cout << digit << endl;
}
else if(n == 7)
{
digit=0.8451*m+1;
cout << digit << endl;
}
else if(n == 8)
{
digit=0.9030*m+1;
cout << digit << endl;
}
else
{
digit=0.9542*m+1;
cout << digit << endl;
}
}
return 0;
}
long long digit 是整數型態 但 digit=0.xxx*m+1; 乘出來不一定是整數吧.....
而且你也分太多case了 只要取log就好了
想請教一下,為什麼這樣到第十個測資會錯??
謝謝!!
#include
using namespace std;
int main()
{
long long n,m;
long long digit;
while(cin >> n >> m)
{
if(n == 1)
cout << 1 << endl;
else if(n == 10)
cout << m+1 << endl;
else if(n == 2)
{
digit=0.3010*m+1;
cout << digit << endl;
}
else if(n == 3)
{
digit=0.4471*m+1;
cout << digit << endl;
}
else if(n == 4)
{
digit=0.6020*m+1;
cout << digit << endl;
}
else if(n == 5)
{
digit=0.6990*m+1;
cout << digit << endl;
}
else if(n == 6)
{
digit=0.7781*m+1;
cout << digit << endl;
}
else if(n == 7)
{
digit=0.8451*m+1;
cout << digit << endl;
}
else if(n == 8)
{
digit=0.9030*m+1;
cout << digit << endl;
}
else
{
digit=0.9542*m+1;
cout << digit << endl;
}
}
return 0;
}
long long digit 是整數型態 但 digit=0.xxx*m+1; 乘出來不一定是整數吧.....
而且你也分太多case了 只要取log就好了
因為我一開始不知道可以用#include<cmath>
所以我直接把log的值查出來