Permutationen problem
-
Hi Leute ich bin neu im Forum,
ich habe eine Probelm.
Ich habe ein Programm geschrieben, der der die Permutationen von drei Zahlen ausrechnen kann.
Bei einem Punkt habe ich einen Problem, immmer, wenn er was gerechnet hat, soll er das Ergebnis abspeichern, dasskrieg ich irgendwie nicht hin.Hier ist der code:
// next_permutation #include <iostream> #include <algorithm> using namespace std; int main () { int myints[] = {1,2,3}; float array[50]; cout << "The 3! possible permutations with 3 elements:\n"; sort (myints,myints+3); do { cout << myints[0] << " " << myints[1] << " " << myints[2] << endl<< endl; int a = myints[0]; int b = myints[1]; int c = myints[2]; float K = 0; float H = 0; float I = 0; if (a == 1) { K = 0.2; } if (a == 2) { K = 0.3; } if (a ==3) { K = 0.26; } if (a == 1 && b == 2 ) { H = 0.3; } if (a == 1 && b == 3) { H = 0.26; } if (a == 2 && b == 1) { H = 0.26; } if (a == 2 && b == 3) { H = 0.3; } if (a == 3 && b == 1) { H = 0.3; } if (a == 3 && b == 2) { H = 0.26; } if (b == 1 && c == 2) { I = 0.3; } if (b == 1 && c == 3) { I = 0.26; } if (b == 2 && c == 1) { I = 0.26; } if (b == 2 && c == 3) { I = 0.3; } if (b == 3 && c == 1) { I = 0.3; } if (b == 3 && c == 2) { I = 0.26; } float i = 0; i = K*H*I ; cout<< i << endl << endl; } while ( next_permutation (myints,myints+3) ); system("PAUSE"); return 0; }Also er sollte jedes mal, wenn er i = K*H*I ausgrechnet hat, sie speichern, aber dass funktioniert nicht richtig, denn am ende sollte die Summe der Ganzen Ergebnisse ausgerechnet werden.
Danke voraus.
-
ich würd nen vector nehmen, wenn ich dich richtig verstanden hab
#include <vector> ... int main() { vector<float> my_floats; while(...) { ... my_floats.push_back(i); // i in vector hinzufügen } for (auto i = my_floats.begin(); i < my_floats.end(); ++i) // werte ausgeben. statt auto vielleicht vector<float>::const_iterator schreiben, wenn du noch kein c++0x hast/benutzt/es nicht weiß wie man es einstellt/ ... :D cout << *i << endl;