kestutis

2 lygis | 1 pamoka| Plytelės

Nov 26th, 2013
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.90 KB | None | 0 0
  1. #include <fstream>
  2. using namespace std;
  3.  
  4. const char duom[] = "Duomenys.txt";
  5. const char rez[] = "Rezultatai.txt";
  6.  
  7. int kiek_reikes_plyteliu(const int x, const int y, int sx, int sy) {
  8.     int rez1, rez2;
  9.     sx *= 100;
  10.     sy *= 100;
  11.     rez1 = (sx/x+(sx%x == 0 ? 0 : 1)) * (sy/y+(sy%y == 0 ? 0 : 1));
  12.     rez2 = (sx/y+(sx%y == 0 ? 0 : 1)) * (sy/x+(sy%x == 0 ? 0 : 1));
  13.     return rez1 > rez2 ? rez2 : rez1;
  14. }
  15.  
  16. /* Dar vienas variantas:
  17. int kiek_reikes_plyteliu(int x, int y, int Sx, int Sy)
  18. {
  19.     int Dx, Dy, Lx, Ly;
  20.  
  21.     Lx = Sx * 100 / x ;
  22.     Ly = Sy * 100 / y ;
  23.  
  24.     Dx = (Sx * 100) % x;
  25.     Dy = (Sy * 100) % y;
  26.  
  27.     if (Dx != 0)
  28.         Lx++;
  29.  
  30.     if (Dy != 0)
  31.         Ly++;
  32.  
  33.     return Lx * Ly;
  34. }
  35. */
  36.  
  37. int main() {
  38.     int x, y, sx, sy;
  39.     ifstream in(duom);
  40.     ofstream out(rez);
  41.     while( in >> x >> y >> sx >> sy )
  42.         out << kiek_reikes_plyteliu(x, y, sx, sy) << endl;  
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment