Quellcode durchsuchen

Add everything so far

Jonatan Gezelius vor 6 Jahren
Commit
180d65cbb2
6 geänderte Dateien mit 202 neuen und 0 gelöschten Zeilen
  1. 10 0
      .gitignore
  2. 42 0
      p100/main.cpp
  3. 24 0
      p10300/p10300.cpp
  4. 20 0
      p11636/p11636.cpp
  5. 23 0
      p12149/p12149.cpp
  6. 83 0
      p497/p497.cpp

+ 10 - 0
.gitignore

@@ -0,0 +1,10 @@
+*.exe
+*.o
+
+
+# Code Blocks specific
+*.cbp
+*.depend
+*.layout
+**/bin
+**/obj

+ 42 - 0
p100/main.cpp

@@ -0,0 +1,42 @@
+
+#include <iostream>
+
+using namespace std;
+
+int main(){
+
+    int i, j, n = 0;
+    int cyc = 0, cyc_max = 0;
+
+
+    while(cin >> i >> j)
+    {
+//        if(cyc_max)
+//            cout << endl;
+
+        cyc_max = 0;
+        for(int q = min(i,j); q <= max(i,j); q++)
+        {
+            n = q;
+            cyc = 1;
+
+            while (n != 1)
+            {
+                if (n%2 == 1) // Om n inte är ett heltal gör ->
+                    n = 3*n+1;
+
+                else
+                    n = n/2; // Om n  är ett heltal gör ->
+
+                cyc++;
+            }
+
+            cyc_max = max(cyc_max, cyc);
+
+        }
+
+        cout << i << " " << j << " " << cyc_max << endl;
+    }
+
+    return 0;
+}

+ 24 - 0
p10300/p10300.cpp

@@ -0,0 +1,24 @@
+#include <iostream>
+
+using namespace std;
+
+int main()
+{
+    int tests, farmers, sqm, animal, ef, sum;
+
+    cin >> tests;
+    for(int t = 0; t < tests; t++)
+    {
+        sum = 0;
+        cin >> farmers;
+
+        for(int f = 0; f < farmers; f++)
+        {
+            cin >> sqm >> animal >> ef;
+            sum += sqm*ef;
+        }
+        cout << sum << endl;
+    }
+
+    return 0;
+}

+ 20 - 0
p11636/p11636.cpp

@@ -0,0 +1,20 @@
+#include <iostream>
+#include <cmath>
+
+using namespace std;
+
+int main(int argc, char *argv[])
+{
+    int number_of_lines = 0, index = 1;
+
+
+    while(cin >> number_of_lines)
+    {
+        if(number_of_lines < 0)
+            break;
+
+        cout << "Case " << index++ << ": " << ceil(log2(number_of_lines)) << endl;
+    }
+
+    return 0;
+}

+ 23 - 0
p12149/p12149.cpp

@@ -0,0 +1,23 @@
+#include <iostream>
+#include <cmath>
+
+int main(int argc, char *argv[])
+{
+    int talet, sum;
+
+    while(std::cin >> talet)
+    {
+        if(!talet)
+            break;
+        std::cin.ignore(1000, '\n');
+
+        sum = 0;
+        for(int i = 0; i <= talet; i++)
+        {
+            sum += pow(i,2);
+        }
+        std::cout << sum << "\n";
+    }
+
+    return 0;
+}

+ 83 - 0
p497/p497.cpp

@@ -0,0 +1,83 @@
+#include <iostream>
+#include <list>
+#include <sstream>
+
+using namespace std;
+
+struct missile
+{
+    int altitude;
+    int length;
+    list<missile>::iterator next;
+};
+
+int main()
+{
+    int max = 0;
+
+    list<missile> incoming;
+    list<missile>::iterator longest, the_way;
+
+    int test_cases;
+    missile missile_entry;
+    missile_entry.next = incoming.end();
+    missile_entry.length = 1;
+    string line;
+
+
+    cin >> test_cases;
+    cin.ignore();
+    cin.ignore();
+
+
+    for(int t = 0; t < test_cases; t++)
+    {
+        incoming.clear();
+        max = 0;
+        longest = incoming.end();
+
+
+        while(getline(cin, line))
+        {
+            if(line.empty())
+                break;
+
+            istringstream iss_line(line);
+            iss_line >> missile_entry.altitude;
+            incoming.push_back(missile_entry);
+        }
+
+        for(auto i = incoming.end(); i != incoming.begin(); i--)
+        {
+            prev(i)->length = 1;
+
+            for(auto y = i; y != incoming.end(); y++)
+            {
+                if((y->altitude > prev(i)->altitude) && ((y->length) >= prev(i)->length))
+                {
+                    prev(i)->length = y->length + 1;
+                    prev(i)->next = y;
+                }
+            }
+
+            if(prev(i)->length > max)
+            {
+                max = prev(i)->length;
+                longest = prev(i);
+            }
+        }
+
+        cout << "Max hits: " << max << endl;
+        the_way = longest;
+        while(the_way != incoming.end())
+        {
+            cout << the_way->altitude << endl;
+            the_way = the_way->next;
+        }
+
+        if(t != test_cases-1)
+            cout << endl;
+    }
+
+    return 0;
+}