Pārlūkot izejas kodu

Fixed input issue, basic testing (like 2 tests) worked!

tarfeef101 7 gadi atpakaļ
vecāks
revīzija
a0a04d906c
2 mainītis faili ar 16 papildinājumiem un 11 dzēšanām
  1. BIN
      q5/q5_test
  2. 16 11
      q5/q5a.cpp

BIN
q5/q5_test


+ 16 - 11
q5/q5a.cpp

@@ -3,6 +3,7 @@
 #include <cstdlib>
 #include <string>
 #include <sstream>
+using namespace std;
 
 /*int n;
 int twon = 2 * n;
@@ -38,9 +39,11 @@ return false;
 ================*/
 int main()
 {
+    string en;
     int n;
-    std::cin >> n; // get the length of the array we are manipulating
-    std::cout << n << std::endl;
+    getline(cin, en);
+    stringstream cast(en);
+    cast >> n; // get the length of the array we are manipulating
 
     int * a = (int *) malloc(n * sizeof(int));
     int * b = (int *) malloc(n * sizeof(int));
@@ -48,13 +51,15 @@ int main()
     for (int i = 0; i < n; ++i)
     {
         // get each line which is 2 ints, put into A and B
-        std::string input;
-        std::getline(std::cin, input);
-        std::stringstream nums(input);
+        string input;
+        getline(cin, input);
+        stringstream nums(input);
         //input >> nums;
-        
+       
         nums >> a[i];
-        nums >> b[i];
+        cout << "This is a[" << i << "] " << a[i] << endl;
+	nums >> b[i];
+	cout << "This is b[" << i << "] " << b[i] << endl;
     }
     
     /*
@@ -89,23 +94,23 @@ int main()
     }
     
     // sort c, with time complexity n squared log (n squared), which reduces to n squared log n
-    std::sort(c, c + clen);
+    sort(c, c + clen);
     
     // for reach sum in a, see if it is in c. n squared checks of log (n squared), or n squared log n
     for (int i = 0; i < clen; ++i)
     {
         for (int j = (i + 1); j < n; ++j)
         {
-            if (std::binary_search(c, (c + clen), (a[i] + a[j])))
+            if (binary_search(c, (c + clen), (a[i] + a[j])))
             {
                 free(a); free (b); free(c);
-		std::cout << 1 << std::endl;
+		cout << 1 << endl;
                 return true;
             }
         }
     }
     
     free(a); free(b); free(c);
-    std::cout << 0 << std::endl;
+    cout << 0 << endl;
     return false;
 }