Source code for submission s852

Go to diff to previous submission

fl2.cpp

  1. // Fractional Lotion
  2. // VOGEL BROTHERS
  3.  
  4. #include <cstdlib>
  5. #include<cmath>
  6. #include <iostream>
  7. using namespace std;
  8.  
  9. int func (int n) {
  10. int x,twoN, yInt, count;
  11.  
  12. float yFloat;
  13. twoN = n*2;
  14. count = 0;
  15. // calculate solutions
  16. for (x = n+1; x <= twoN; x++) {
  17. int nx, xmn; // nx = n*x, xmn = x - n
  18. nx = n*x;
  19. xmn = x-n;
  20. yFloat = (float) nx / (float) xmn;
  21. if (abs(yFloat - (int) yFloat) < 0.00001) {
  22. count ++;
  23. }
  24. }
  25. return count;
  26. }
  27.  
  28.  
  29. int main () {
  30. char dummy, dummy2;
  31. char temp[10];
  32. int n;
  33.  
  34. while (cin.getline(temp, 10)) {
  35.  
  36. n = atoi(temp+2);
  37. // print result
  38. cout << func(n) << endl;
  39. }
  40.  
  41. return 0;
  42. }
  43.  
  44.  
  45.  

Diff to submission s662

fl1.cpp

--- c5.s662.cteam047.fl.cpp.0.fl1.cpp
+++ c5.s852.cteam047.fl.cpp.0.fl2.cpp
@@ -9,8 +9,5 @@
 int func (int n) {
         int x,twoN, yInt, count;
-        bool * results = new bool[n];
-        for (int i = 0; i < n; i++) {
-                results[i] = false;
-        }
+        
         float yFloat;
         twoN = n*2;
@@ -23,11 +20,7 @@
                 yFloat = (float) nx / (float) xmn;
                 if (abs(yFloat - (int) yFloat) < 0.00001) {
-                        if (results[xmn-1] != true) {
-                                results[xmn-1] = true;
                                 count ++;
-                        }
                 }
         }
-        delete[]results;
         return count;
 }