lehrkraefte:blc:informatik:ffprg2017:ln:ln

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
lehrkraefte:blc:informatik:ffprg2017:ln:ln [2017/11/10 06:53] – created Ivo Blöchligerlehrkraefte:blc:informatik:ffprg2017:ln:ln [2017/11/10 07:39] (current) – [Programmieren mit C++] Ivo Blöchliger
Line 1: Line 1:
 +===== Programmieren mit C++ =====
 +=== Installation einer IDE ===
 +  * Unter Linux: gcc + Text-Editor
 +  * Windows: gcc + MINGW + Texteditor oder VisualC++?
 +  * Mac? Keine Ahnung... wohl gcc + Text-Editor oder X-Code?
  
 +=== Hello World ===
 +<code c++ hello.cpp>
 +// Kommentar
 +#include <iostream>  // Für Ein- und Ausgabe
 +
 +/* Mehrzeiliger Kommentar
 + Damit einfach cout anstatt std::cout geschrieben werden kann.
 + Gilt auch für endl anstatt std:endl
 +*/
 +using namespace std;
 +
 +// Start Hauptprogramm. Könnte int zurückgeben als Fehlercode
 +// 0 heisst kein Fehler.
 +int main() {
 +  cout << "Hello world!" << endl;
 +}
 +
 +</code>
 +
 +===== SOI Aufgaben =====
 +==== Task 1, Sushi ====
 +=== Subtask 1 ===
 +<code c++ sub1.cpp>
 +#include <iostream> 
 +using namespace std;
 +
 +// Solve problem
 +int solve(int n, int s, int p[]) {
 +  // Solve problem here
 +  // Return solution
 +  return 42;
 +}
 +
 +
 +int main() {
 +  int t=0;  // number of test cases
 +  cin >> t;
 +  // Repeat over all test cases
 +  for (int i=0; i<t; i++) {
 +    int n=0;
 +    cin >> n; // number of sushis
 +    int s=0;
 +    cin >> s; // price of bottle
 +
 +    int p[n]; // Array for sushi prices
 +    for (int j=0; j<n; j++) {
 +      cin >> p[j];  // Read sushi price
 +    }
 +    // Solve and output solution
 +    cout << "Case #" << i << ": " << solve(n,s,p) << endl;
 +  }
 +}
 +</code>
 +
 +== Testdaten ==
 +<code txt sub1.txt>
 +2
 +2 0
 +16 42
 +2 0
 +100 64
 +</code>
 +
 +== Ausführen ==
 +Nach dem Compilieren z.B. mit
 +<code bash>
 +  ./sub1.exe < sub1.txt
 +</code>
 +wird der Inhalt der Datei sub1.txt eingelesen, als ob dies auf der Tastatur eingegeben worden wäre.
 +== Makefile ==
 +Für jene ohne IDE, hier ein generisches Makefile:
 +<code makefile Makefile>
 +SOURCES=$(wildcard *.cpp)
 +TARGETS=$(patsubst %.cpp,%.exe,$(SOURCES))
 +
 +all: $(TARGETS)
 +
 +%.exe: %.cpp
 + g++ $< -o $@
 +
 +clean:
 + rm -r *~ *.exe
 +</code>