summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSanto Cariotti <sancn@live.com>2017-04-13 11:02:43 +0200
committerGitHub <noreply@github.com>2017-04-13 11:02:43 +0200
commit951a1bb4b9dafb7a368155e066e66133a7d166a4 (patch)
tree2c64c18243c541c8d92cd73ac8b46c974e035d3b
parentaf1befc64570360d4f1e6f85b94d2546612a8dd0 (diff)
Reverse
La ricerca avviene anche in senso inverso
-rw-r--r--scommesse.cpp26
1 files changed, 17 insertions, 9 deletions
diff --git a/scommesse.cpp b/scommesse.cpp
index 0ba6e3c..2fa0936 100644
--- a/scommesse.cpp
+++ b/scommesse.cpp
@@ -7,9 +7,9 @@
* 8 2
*/
#include <iostream>
-#include <iostream>
#include <fstream>
#include <vector>
+#include <algorithm>
using namespace std;
@@ -25,13 +25,11 @@ void cOutPresente(vector<int>& kr, int x)
kr.push_back(x);
}
-void fCarte(int carte[], int N, int s)
+void fCarte(vector<int> c, int N, int s)
{
int i;
- vector<int> c;
vector<int>::iterator it;
vector<int>::iterator start;
- for(i = 0; i < N; i++) c.push_back(carte[i]);
while(c.size() > 1) {
//for(it = c.begin(); it != c.end(); it++) cout << *it << ' '; cout << endl;
@@ -56,17 +54,27 @@ int main()
int N, i;
in >> N;
- int* carte = new int[N];
+ int x;
+ vector<int> carteV;
- for(i = 0; i < N; i++) in >> carte[i];
+ for(i = 0; i < N; i++) {
+ in >> x;
+ carteV.push_back(x);
+ }
for(int i = 0; i < N; i++) {
- fCarte(carte, N, i);
+ fCarte(carteV, N, i);
}
+
+ reverse(carteV.begin(), carteV.end());
+
+ for(int i = 0; i < N; i++) {
+ fCarte(carteV, N, i);
+ }
+
out << carteOut.size() << endl;
for(vector<int>::iterator ite = carteOut.begin(); ite != carteOut.end(); ite++) out << *ite << ' ';
-
- delete[] carte;
+
out.close();
in.close();
return 0;