[Logo] Mendo Judge Discussion Board - Forums
  [Search] Search   [Recent Topics] Recent Topics   [Hottest Topics] Hottest Topics   [Members]  Member Listing   [Groups] Back to home page 
Messages posted by: VasilK
Forum Index » Profile for VasilK » Messages posted by VasilK
Author Message
Фала, тоа го реши почетниот прболем али сеа ми паѓа на тест примери каде што нзс е поголемо од 2^32-1
пробав nzs да го декларирам како long long наместо int али пак не иде...

#include <iostream>
using namespace std;
int main()
{
float old_price, new_price;
cin >> old_price >> new_price;
old_price*=100;
new_price*=100;
int price1=(int)old_price, price2=(int)new_price, nzd;
while(1==1)
{
if(price1==0)
{
nzd=price2;
break;
}
else if(price2==0)
{
nzd=price1;
break;
}
else
{
price1=price1%price2;
int temp;
temp=price1;
price1=price2;
price2=temp;
}
}
long long nzs;
nzs=(int)old_price*(int)new_price/nzd;
int M, N;
M=nzs/(int)old_price;
N=nzs/(int)new_price-M;
cout << nzs << endl;
cout << "KUPI " << M << " DOBIJ " << N << " GRATIS" << endl; system("pause");
}
Може ли некој да ми каже зашто кога внесувам 0.99 и 0.53 во програмава наместо 0.99 чита 0.99000001 и наместо 0.53 чита 0.529999971??
ај за 0.99 не е проблем али после коа го множам 0.53 со 100 и го претварам во int ми го заокружува на 52
Фала однапред

#include <iostream>
using namespace std;
int main()
{
float old_price, new_price;
cin >> old_price >> new_price;
old_price*=100;
new_price*=100;
int price1=(int)old_price, price2=(int)new_price, nzd, nzs;
while(1==1)
{
if(price1==0)
{
nzd=price2;
break;
}
else if(price2==0)
{
nzd=price1;
break;
}
else
{
price1=price1%price2;
int temp;
temp=price1;
price1=price2;
price2=temp;
}
}
nzs=(int)old_price*(int)new_price/nzd;
int M, N;
M=nzs/(int)old_price;
N=nzs/(int)new_price-M;
cout << "KUPI " << M << " DOBIJ " << N << " GRATIS" << endl;
}
 
Forum Index » Profile for VasilK » Messages posted by VasilK
Go to:   
Powered by JForum 2.1.8 © JForum Team