From 483d63fa7249ad8d6020680c48c3cf6df35010b3 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Wed, 26 Apr 2017 16:37:39 +0200 Subject: Moved all C++ files into CPP folder --- DFS.cpp | 39 ---------------- Es 3.cpp | 109 ------------------------------------------- Es5.cpp | 46 ------------------ Es6.cpp | 38 --------------- arrayMinMax.cc | 35 -------------- ascensore.cc | 90 ----------------------------------- biblioteca.cc | 57 ---------------------- bicicletta.c++ | 62 ------------------------ borsa.cc | 32 ------------- carte.cpp | 105 ----------------------------------------- conversioneBinariaDec.cc | 42 ----------------- cpp/DFS.cpp | 39 ++++++++++++++++ cpp/Es 3.cpp | 109 +++++++++++++++++++++++++++++++++++++++++++ cpp/Es5.cpp | 46 ++++++++++++++++++ cpp/Es6.cpp | 38 +++++++++++++++ cpp/arrayMinMax.cc | 35 ++++++++++++++ cpp/ascensore.cc | 90 +++++++++++++++++++++++++++++++++++ cpp/biblioteca.cc | 57 ++++++++++++++++++++++ cpp/bicicletta.c++ | 62 ++++++++++++++++++++++++ cpp/borsa.cc | 32 +++++++++++++ cpp/carte.cpp | 105 +++++++++++++++++++++++++++++++++++++++++ cpp/conversioneBinariaDec.cc | 42 +++++++++++++++++ cpp/crittografia.cc | 89 +++++++++++++++++++++++++++++++++++ cpp/es4.cpp | 67 ++++++++++++++++++++++++++ cpp/grafo.cpp | 73 +++++++++++++++++++++++++++++ cpp/hanoi.cc | 29 ++++++++++++ cpp/lswf.cpp | 67 ++++++++++++++++++++++++++ cpp/numeri.cc | 50 ++++++++++++++++++++ cpp/palindromo.cc | 25 ++++++++++ cpp/parentesi.cpp | 58 +++++++++++++++++++++++ cpp/planet.cc | 72 ++++++++++++++++++++++++++++ cpp/scommesse.cpp | 81 ++++++++++++++++++++++++++++++++ cpp/sorveglianza.c++ | 88 ++++++++++++++++++++++++++++++++++ cpp/substring.cc | 22 +++++++++ crittografia.cc | 89 ----------------------------------- es4.cpp | 67 -------------------------- grafo.cpp | 73 ----------------------------- hanoi.cc | 29 ------------ lswf.cpp | 67 -------------------------- numeri.cc | 50 -------------------- palindromo.cc | 25 ---------- parentesi.cpp | 58 ----------------------- planet.cc | 72 ---------------------------- scommesse.cpp | 81 -------------------------------- sorveglianza.c++ | 88 ---------------------------------- substring.cc | 22 --------- 46 files changed, 1376 insertions(+), 1376 deletions(-) delete mode 100644 DFS.cpp delete mode 100644 Es 3.cpp delete mode 100644 Es5.cpp delete mode 100644 Es6.cpp delete mode 100644 arrayMinMax.cc delete mode 100644 ascensore.cc delete mode 100644 biblioteca.cc delete mode 100644 bicicletta.c++ delete mode 100644 borsa.cc delete mode 100644 carte.cpp delete mode 100644 conversioneBinariaDec.cc create mode 100644 cpp/DFS.cpp create mode 100644 cpp/Es 3.cpp create mode 100644 cpp/Es5.cpp create mode 100644 cpp/Es6.cpp create mode 100644 cpp/arrayMinMax.cc create mode 100644 cpp/ascensore.cc create mode 100644 cpp/biblioteca.cc create mode 100644 cpp/bicicletta.c++ create mode 100644 cpp/borsa.cc create mode 100644 cpp/carte.cpp create mode 100644 cpp/conversioneBinariaDec.cc create mode 100644 cpp/crittografia.cc create mode 100644 cpp/es4.cpp create mode 100644 cpp/grafo.cpp create mode 100644 cpp/hanoi.cc create mode 100644 cpp/lswf.cpp create mode 100644 cpp/numeri.cc create mode 100644 cpp/palindromo.cc create mode 100644 cpp/parentesi.cpp create mode 100644 cpp/planet.cc create mode 100644 cpp/scommesse.cpp create mode 100644 cpp/sorveglianza.c++ create mode 100644 cpp/substring.cc delete mode 100644 crittografia.cc delete mode 100644 es4.cpp delete mode 100644 grafo.cpp delete mode 100644 hanoi.cc delete mode 100644 lswf.cpp delete mode 100644 numeri.cc delete mode 100644 palindromo.cc delete mode 100644 parentesi.cpp delete mode 100644 planet.cc delete mode 100644 scommesse.cpp delete mode 100644 sorveglianza.c++ delete mode 100644 substring.cc diff --git a/DFS.cpp b/DFS.cpp deleted file mode 100644 index fda5a33..0000000 --- a/DFS.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include -#define BIANCO 0 //Non Visitato -#define NERO 2 //Visitato -#define GRIGIO 1 //Non Finito -#define INF 999999 -#include -#include -#include -#define MAXN 9999 -#define INDEF -1 -#include -using namespace std; -int V=9; -int matriceAdj[MAXN][MAXN]; - int colore[MAXN]; - //DFS Tramite matrice di adiacenza - void dfsVisit (int u) - { - colore[u]= GRIGIO; - for (int i=0;i -#define BIANCO 0 //Non Visitato -#define NERO 2 //Visitato -#define GRIGIO 1 //Non Finito -#define INF 999999 -#include -#include -#include -#define MAXN 9999 -#define INDEF -1 -#include -using namespace std; -typedef pair p; -std::priority_queue, std::greater

> Q; -int V,E; -int matriceAdj[MAXN][MAXN]; -int T; -struct nodo { - vector adj; - int inizio,fine; -}no[MAXN]; - int colore[MAXN]; - bool Ciclico=false; - bool dfsVisit (int u) - { - cout<>V>>E; - int a,b; - for (int i=0;i>a>>b; - no[a].adj.push_back(b); - } - dfs(); - for (int i=0;i -#define BIANCO 0 //Non Visitato -#define NERO 2 //Visitato -#define GRIGIO 1 //Non Finito -#define INF 999999 -#include -#include -#include -#define MAXN 9999 -#define INDEF -1 -#include -using namespace std; -typedef pair p; -struct nodo{ - vector adj; - vector p; -}; - -int main(int argc, char** argv) { - int v,e; - int sorgente; - nodo no[v]; - - priority_queue

Q; - int peso[v]; - Q.push(p(0,sorgente)); - - while(!Q.empty()) - { - pair a=Q.top(); - Q.pop(); - if (a.first > peso[a.second]) - continue; - - for (int i=0;ia.first+ no[a.second].p[i]) - { - peso[no[a.second].adj[i]]=a.first + no[a.second].p[i]; - Q.push(p(peso[no[a.second].adj[i]],no[a.second].adj[i])); - } - } - - } - return 0; -} diff --git a/Es6.cpp b/Es6.cpp deleted file mode 100644 index 9907eb9..0000000 --- a/Es6.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include -#include -using namespace std; -/* run this program using the console pauser or add your own getch, system("pause") or input loop */ - -int main(int argc, char** argv) { - int v=5; - int matrice[v][v]; - for (int i=0;i - -using namespace std; - -int main(void) -{ - int a[] = {5,14,9,8,10,65,32,1,6,78}; - int tot = sizeof a / sizeof(int); - int t, i, j, minore = a[0], maggiore = a[tot-1]; - - for(i = 0; i < tot; i++) - { - for(j = 0; j < tot-1; j++) - { - if(a[j] > a[j+1]){ - t = a[j+1]; - a[j+1] = a[j]; - a[j] = t; - } - } - } - - //for(i = 0; i < tot; i++) cout << a[i] << endl; - - /*for(int i = 0; i < tot; i++) - { - if(a[i] < minore) minore = a[i]; - else if(a[i] > maggiore) maggiore = a[i]; - }*/ - - cout << minore << endl; - cout << maggiore << endl; - - return 0; -} diff --git a/ascensore.cc b/ascensore.cc deleted file mode 100644 index 8e69964..0000000 --- a/ascensore.cc +++ /dev/null @@ -1,90 +0,0 @@ -#include -#include -#include -#include - -class Ascensore -{ -private: - unsigned short int floor; - bool doors; - unsigned short int maxFloor; -public: - Ascensore(unsigned short int plan = 0) {floor = plan; maxFloor = 5;} - void Up(void); - void Down(void); - void Doors(void); - void getFloor(void); -}; - -void _clear(void); - -using namespace std; - -int main(void) -{ - char choose; - Ascensore *ascensore = new Ascensore(); - do { - ascensore->getFloor(); - cin >> choose; - choose = tolower(choose); - if(choose == 'u' || choose == 'd') ascensore->Doors(); - sleep(2); - switch(choose) - { - case 'u' : ascensore->Up(); break; - case 'd' : ascensore->Down(); break; - case 'e' : break; - } - _clear(); - if(choose == 'u' || choose == 'd') ascensore->Doors(); - } while(choose != 'e'); - - cout << "SEI USCITO DALL'ASCENSORE CON SUCCESSO!"; - - return 0; -} - -void _clear(void) -{ - #ifdef OS_WINDOWS - system("CLS"); - #else - system("clear"); - #endif -} - -void Ascensore::getFloor(void) -{ - if(floor == maxFloor) cout << "Sei arrivato all'ultimo piano" << endl; - if(floor == 0) cout << "Non puoi scendere più di così" << endl; - cout << "SEI ATTUALMENTE AL PIANO " << floor << endl; - cout << "\nQUALE AZIONE SI VUOLE COMPIERE?" << endl; - cout << "U - salire" << endl; - cout << "D - scendere" << endl; - cout << "E - Uscire" << endl; - cout << "> "; -} - -void Ascensore::Up(void) -{ - if(floor < maxFloor) floor+=1; -} - -void Ascensore::Down(void) -{ - if(floor > 0) floor-=1; -} - -void Ascensore::Doors(void) -{ - if(doors == true) - { - cout << "> APERTURA PORTE" << endl; - doors = false; - } else { - cout << "> CHIUSURA PORTE..." << endl; - doors = true; - } -} diff --git a/biblioteca.cc b/biblioteca.cc deleted file mode 100644 index 85cd80f..0000000 --- a/biblioteca.cc +++ /dev/null @@ -1,57 +0,0 @@ -#include -#include -#include -#include - -using namespace std; - -int main(void) -{ - ifstream filein; - ofstream fileout; - - filein.open("input.txt"); - fileout.open("output.txt"); - - time_t rawtime; - struct tm * timeinfo; - - int num[4], i = 0, j = 1, diff, tot[2]; - char ch; - string cc; - - while(!filein.eof()) - { - filein.get(ch); - if(ch != ' '){ - cc+=ch; - istringstream(cc) >> num[i]; - }else { - i++; - cc = ""; - } - } - - time(&rawtime); - timeinfo = localtime(&rawtime); - - for(i = 0; i < 2; i++){ - timeinfo->tm_year = 2001-1900; - timeinfo->tm_mon = num[j]-1; - timeinfo->tm_mday = num[j-1]; - - mktime(timeinfo); - - tot[i] = timeinfo->tm_yday+1; - j = 3; - } - - diff = tot[1] - tot[0]; - - fileout << diff; - - filein.close(); - fileout.close(); - - return 0; -} diff --git a/bicicletta.c++ b/bicicletta.c++ deleted file mode 100644 index bb42031..0000000 --- a/bicicletta.c++ +++ /dev/null @@ -1,62 +0,0 @@ -/* INPUT: -3 4 -2 -3 -1 -1 3 -1 2 -3 2 -3 1 - -OUTPUT: -3 -*/ - -#include -#include - -using namespace std; - -int main(void) -{ - ifstream in; - ofstream out; - in.open("input.txt"); - out.open("output.txt"); - - int numBici, sorpassi, i, x, j, y, m[2]; - in >> numBici; - in >> sorpassi; - - int* posBici = new int[numBici]; - - // posizioni di base - for(i = 0; i < numBici; i++) - in >> posBici[i]; - - // sorpassi - for(i = 0; i < sorpassi; i++) - { - in >> x; - in >> y; - - for(j = 0; j < numBici; j++) - { - if(posBici[j] == x) m[0] = j; //indice valore che sorpassa - - if(posBici[j] == y) m[1] = j; //indice valore che viene sorpassato - } - - posBici[m[0]] = y; - posBici[m[1]] = x; - } - - out << posBici[0]; - - delete[] posBici; - - in.close(); - out.close(); - - return 0; -} diff --git a/borsa.cc b/borsa.cc deleted file mode 100644 index 05fdd85..0000000 --- a/borsa.cc +++ /dev/null @@ -1,32 +0,0 @@ -#include - -using namespace std; - -int main(void) -{ - int a[] = {13,24,7,8,6,15,2,21,17,7,3,19,20,1}; - int minore, diffp, diff = 0, x, y; - int tot = sizeof a/sizeof(int); - - for(int i = 0; i < tot; i++) - { - minore = a[i]; - - for(int j = i; j < tot-1; j++) - { - if(a[j] == minore) continue; - else if(a[j] > minore) diffp = a[j] - minore; - if(diffp > diff && diffp > 0) { - x = i; - y = j; - diff = diffp; - } - } - } - - cout << "Ti conviene comprare a " << a[x] << " giorno " << x+1 << " e vendere a " << a[y] << " giorno " << y+1 << endl; - cout << "Il tuo guadagno sarebbe: " << diff; - - - return 0; -} diff --git a/carte.cpp b/carte.cpp deleted file mode 100644 index 697622a..0000000 --- a/carte.cpp +++ /dev/null @@ -1,105 +0,0 @@ -/* -INPUT: -18 -12 6 -11 8 -15 8 -15 20 -13 18 -12 23 -11 40 -15 19 -11 25 -13 36 -15 12 -12 18 -17 11 -23 9 -28 22 -35 26 -11 23 -15 12 - -output: -11 96 */ -#include -#include - -using namespace std; - -struct punteggioGiocatori -{ - int idGiocatore; - int punteggio; -} player[100]; - -int ricercaIdGiocatore(int valore, struct punteggioGiocatori* p); - -int main() -{ - ifstream in("input.txt"); - ofstream out("output.txt"); - - int N, i, pPlayer, j = 0, rID, nVal, t[2]; - bool s; - in >> N; - - for(i = 0; i < N; i++) { - player[i].idGiocatore = 0; - player[i].punteggio = 0; - } - - for(i = 0; i < N; i++) { - in >> pPlayer; - rID = ricercaIdGiocatore(pPlayer, player); - if(rID == -1) { - player[j].idGiocatore = pPlayer; - in >> player[j].punteggio; - j++; - } else { - in >> nVal; - player[rID].punteggio += nVal; - } - } - int last = j; - do { - s = false; - for(int k = 0; k < last; k++) - { - if(player[k].punteggio < player[k+1].punteggio) { - t[0] = player[k].idGiocatore; - t[1] = player[k].punteggio; - - player[k].idGiocatore = player[k+1].idGiocatore; - player[k].punteggio = player[k+1].punteggio; - - player[k+1].idGiocatore = t[0]; - player[k+1].punteggio = t[1]; - - s = true; - } - - } - - last--; - } while(s); - - out << player[0].idGiocatore << " " << player[0].punteggio << endl; - - in.close(); - out.close(); -} - -int ricercaIdGiocatore(int valore, struct punteggioGiocatori* p) -{ - int rID = -1; - for(int i = 0; i < 100; i++) - { - if(p[i].idGiocatore == valore) { - rID = i; - break; - } - } - - return rID; -} diff --git a/conversioneBinariaDec.cc b/conversioneBinariaDec.cc deleted file mode 100644 index e88a2fb..0000000 --- a/conversioneBinariaDec.cc +++ /dev/null @@ -1,42 +0,0 @@ -#include -#include -#include - -using namespace std; - -const int b = 32; - -int main() -{ - int v[b] = {0}; //tutti i valori sono uguali a 0 - char str[b]; - int valVuoto, i, j; - int num = 0; - - cin >> str; - /* se la lunghezza della stringa è inferiore a quella della base, indica da quale punto è vuota */ - if(strlen(str) < b) - valVuoto = strlen(str); - - /* ordina i valori in modo tale da spostarli a blocco, ovvero entrambi gli indici si incrementano - man mano che ordinano il vettore degli interi. La base - la prima X di 'str' è l'inizio dell'ordine - del vettore degli int. - - Seguendo questa logica e questo esempio: - STR - - 1 0 x x x x x x - - V - - x x x x x x 1 0 - */ - for(i = b - valVuoto, j = 0; i < b; i++, j++) - v[i] = str[j] - '0'; - - //il vettore viene letto in ordine decrescente, mentre le potenze in crescente - for(i = b - 1, j = 0; i > -1; i--, j++) - num += v[i] * pow(2, j); - - cout << num << endl; - - return 0; -} diff --git a/cpp/DFS.cpp b/cpp/DFS.cpp new file mode 100644 index 0000000..fda5a33 --- /dev/null +++ b/cpp/DFS.cpp @@ -0,0 +1,39 @@ +#include +#define BIANCO 0 //Non Visitato +#define NERO 2 //Visitato +#define GRIGIO 1 //Non Finito +#define INF 999999 +#include +#include +#include +#define MAXN 9999 +#define INDEF -1 +#include +using namespace std; +int V=9; +int matriceAdj[MAXN][MAXN]; + int colore[MAXN]; + //DFS Tramite matrice di adiacenza + void dfsVisit (int u) + { + colore[u]= GRIGIO; + for (int i=0;i +#define BIANCO 0 //Non Visitato +#define NERO 2 //Visitato +#define GRIGIO 1 //Non Finito +#define INF 999999 +#include +#include +#include +#define MAXN 9999 +#define INDEF -1 +#include +using namespace std; +typedef pair p; +std::priority_queue, std::greater

> Q; +int V,E; +int matriceAdj[MAXN][MAXN]; +int T; +struct nodo { + vector adj; + int inizio,fine; +}no[MAXN]; + int colore[MAXN]; + bool Ciclico=false; + bool dfsVisit (int u) + { + cout<>V>>E; + int a,b; + for (int i=0;i>a>>b; + no[a].adj.push_back(b); + } + dfs(); + for (int i=0;i +#define BIANCO 0 //Non Visitato +#define NERO 2 //Visitato +#define GRIGIO 1 //Non Finito +#define INF 999999 +#include +#include +#include +#define MAXN 9999 +#define INDEF -1 +#include +using namespace std; +typedef pair p; +struct nodo{ + vector adj; + vector p; +}; + +int main(int argc, char** argv) { + int v,e; + int sorgente; + nodo no[v]; + + priority_queue

Q; + int peso[v]; + Q.push(p(0,sorgente)); + + while(!Q.empty()) + { + pair a=Q.top(); + Q.pop(); + if (a.first > peso[a.second]) + continue; + + for (int i=0;ia.first+ no[a.second].p[i]) + { + peso[no[a.second].adj[i]]=a.first + no[a.second].p[i]; + Q.push(p(peso[no[a.second].adj[i]],no[a.second].adj[i])); + } + } + + } + return 0; +} diff --git a/cpp/Es6.cpp b/cpp/Es6.cpp new file mode 100644 index 0000000..9907eb9 --- /dev/null +++ b/cpp/Es6.cpp @@ -0,0 +1,38 @@ +#include +#include +using namespace std; +/* run this program using the console pauser or add your own getch, system("pause") or input loop */ + +int main(int argc, char** argv) { + int v=5; + int matrice[v][v]; + for (int i=0;i + +using namespace std; + +int main(void) +{ + int a[] = {5,14,9,8,10,65,32,1,6,78}; + int tot = sizeof a / sizeof(int); + int t, i, j, minore = a[0], maggiore = a[tot-1]; + + for(i = 0; i < tot; i++) + { + for(j = 0; j < tot-1; j++) + { + if(a[j] > a[j+1]){ + t = a[j+1]; + a[j+1] = a[j]; + a[j] = t; + } + } + } + + //for(i = 0; i < tot; i++) cout << a[i] << endl; + + /*for(int i = 0; i < tot; i++) + { + if(a[i] < minore) minore = a[i]; + else if(a[i] > maggiore) maggiore = a[i]; + }*/ + + cout << minore << endl; + cout << maggiore << endl; + + return 0; +} diff --git a/cpp/ascensore.cc b/cpp/ascensore.cc new file mode 100644 index 0000000..8e69964 --- /dev/null +++ b/cpp/ascensore.cc @@ -0,0 +1,90 @@ +#include +#include +#include +#include + +class Ascensore +{ +private: + unsigned short int floor; + bool doors; + unsigned short int maxFloor; +public: + Ascensore(unsigned short int plan = 0) {floor = plan; maxFloor = 5;} + void Up(void); + void Down(void); + void Doors(void); + void getFloor(void); +}; + +void _clear(void); + +using namespace std; + +int main(void) +{ + char choose; + Ascensore *ascensore = new Ascensore(); + do { + ascensore->getFloor(); + cin >> choose; + choose = tolower(choose); + if(choose == 'u' || choose == 'd') ascensore->Doors(); + sleep(2); + switch(choose) + { + case 'u' : ascensore->Up(); break; + case 'd' : ascensore->Down(); break; + case 'e' : break; + } + _clear(); + if(choose == 'u' || choose == 'd') ascensore->Doors(); + } while(choose != 'e'); + + cout << "SEI USCITO DALL'ASCENSORE CON SUCCESSO!"; + + return 0; +} + +void _clear(void) +{ + #ifdef OS_WINDOWS + system("CLS"); + #else + system("clear"); + #endif +} + +void Ascensore::getFloor(void) +{ + if(floor == maxFloor) cout << "Sei arrivato all'ultimo piano" << endl; + if(floor == 0) cout << "Non puoi scendere più di così" << endl; + cout << "SEI ATTUALMENTE AL PIANO " << floor << endl; + cout << "\nQUALE AZIONE SI VUOLE COMPIERE?" << endl; + cout << "U - salire" << endl; + cout << "D - scendere" << endl; + cout << "E - Uscire" << endl; + cout << "> "; +} + +void Ascensore::Up(void) +{ + if(floor < maxFloor) floor+=1; +} + +void Ascensore::Down(void) +{ + if(floor > 0) floor-=1; +} + +void Ascensore::Doors(void) +{ + if(doors == true) + { + cout << "> APERTURA PORTE" << endl; + doors = false; + } else { + cout << "> CHIUSURA PORTE..." << endl; + doors = true; + } +} diff --git a/cpp/biblioteca.cc b/cpp/biblioteca.cc new file mode 100644 index 0000000..85cd80f --- /dev/null +++ b/cpp/biblioteca.cc @@ -0,0 +1,57 @@ +#include +#include +#include +#include + +using namespace std; + +int main(void) +{ + ifstream filein; + ofstream fileout; + + filein.open("input.txt"); + fileout.open("output.txt"); + + time_t rawtime; + struct tm * timeinfo; + + int num[4], i = 0, j = 1, diff, tot[2]; + char ch; + string cc; + + while(!filein.eof()) + { + filein.get(ch); + if(ch != ' '){ + cc+=ch; + istringstream(cc) >> num[i]; + }else { + i++; + cc = ""; + } + } + + time(&rawtime); + timeinfo = localtime(&rawtime); + + for(i = 0; i < 2; i++){ + timeinfo->tm_year = 2001-1900; + timeinfo->tm_mon = num[j]-1; + timeinfo->tm_mday = num[j-1]; + + mktime(timeinfo); + + tot[i] = timeinfo->tm_yday+1; + j = 3; + } + + diff = tot[1] - tot[0]; + + fileout << diff; + + filein.close(); + fileout.close(); + + return 0; +} diff --git a/cpp/bicicletta.c++ b/cpp/bicicletta.c++ new file mode 100644 index 0000000..bb42031 --- /dev/null +++ b/cpp/bicicletta.c++ @@ -0,0 +1,62 @@ +/* INPUT: +3 4 +2 +3 +1 +1 3 +1 2 +3 2 +3 1 + +OUTPUT: +3 +*/ + +#include +#include + +using namespace std; + +int main(void) +{ + ifstream in; + ofstream out; + in.open("input.txt"); + out.open("output.txt"); + + int numBici, sorpassi, i, x, j, y, m[2]; + in >> numBici; + in >> sorpassi; + + int* posBici = new int[numBici]; + + // posizioni di base + for(i = 0; i < numBici; i++) + in >> posBici[i]; + + // sorpassi + for(i = 0; i < sorpassi; i++) + { + in >> x; + in >> y; + + for(j = 0; j < numBici; j++) + { + if(posBici[j] == x) m[0] = j; //indice valore che sorpassa + + if(posBici[j] == y) m[1] = j; //indice valore che viene sorpassato + } + + posBici[m[0]] = y; + posBici[m[1]] = x; + } + + out << posBici[0]; + + delete[] posBici; + + in.close(); + out.close(); + + return 0; +} diff --git a/cpp/borsa.cc b/cpp/borsa.cc new file mode 100644 index 0000000..05fdd85 --- /dev/null +++ b/cpp/borsa.cc @@ -0,0 +1,32 @@ +#include + +using namespace std; + +int main(void) +{ + int a[] = {13,24,7,8,6,15,2,21,17,7,3,19,20,1}; + int minore, diffp, diff = 0, x, y; + int tot = sizeof a/sizeof(int); + + for(int i = 0; i < tot; i++) + { + minore = a[i]; + + for(int j = i; j < tot-1; j++) + { + if(a[j] == minore) continue; + else if(a[j] > minore) diffp = a[j] - minore; + if(diffp > diff && diffp > 0) { + x = i; + y = j; + diff = diffp; + } + } + } + + cout << "Ti conviene comprare a " << a[x] << " giorno " << x+1 << " e vendere a " << a[y] << " giorno " << y+1 << endl; + cout << "Il tuo guadagno sarebbe: " << diff; + + + return 0; +} diff --git a/cpp/carte.cpp b/cpp/carte.cpp new file mode 100644 index 0000000..697622a --- /dev/null +++ b/cpp/carte.cpp @@ -0,0 +1,105 @@ +/* +INPUT: +18 +12 6 +11 8 +15 8 +15 20 +13 18 +12 23 +11 40 +15 19 +11 25 +13 36 +15 12 +12 18 +17 11 +23 9 +28 22 +35 26 +11 23 +15 12 + +output: +11 96 */ +#include +#include + +using namespace std; + +struct punteggioGiocatori +{ + int idGiocatore; + int punteggio; +} player[100]; + +int ricercaIdGiocatore(int valore, struct punteggioGiocatori* p); + +int main() +{ + ifstream in("input.txt"); + ofstream out("output.txt"); + + int N, i, pPlayer, j = 0, rID, nVal, t[2]; + bool s; + in >> N; + + for(i = 0; i < N; i++) { + player[i].idGiocatore = 0; + player[i].punteggio = 0; + } + + for(i = 0; i < N; i++) { + in >> pPlayer; + rID = ricercaIdGiocatore(pPlayer, player); + if(rID == -1) { + player[j].idGiocatore = pPlayer; + in >> player[j].punteggio; + j++; + } else { + in >> nVal; + player[rID].punteggio += nVal; + } + } + int last = j; + do { + s = false; + for(int k = 0; k < last; k++) + { + if(player[k].punteggio < player[k+1].punteggio) { + t[0] = player[k].idGiocatore; + t[1] = player[k].punteggio; + + player[k].idGiocatore = player[k+1].idGiocatore; + player[k].punteggio = player[k+1].punteggio; + + player[k+1].idGiocatore = t[0]; + player[k+1].punteggio = t[1]; + + s = true; + } + + } + + last--; + } while(s); + + out << player[0].idGiocatore << " " << player[0].punteggio << endl; + + in.close(); + out.close(); +} + +int ricercaIdGiocatore(int valore, struct punteggioGiocatori* p) +{ + int rID = -1; + for(int i = 0; i < 100; i++) + { + if(p[i].idGiocatore == valore) { + rID = i; + break; + } + } + + return rID; +} diff --git a/cpp/conversioneBinariaDec.cc b/cpp/conversioneBinariaDec.cc new file mode 100644 index 0000000..e88a2fb --- /dev/null +++ b/cpp/conversioneBinariaDec.cc @@ -0,0 +1,42 @@ +#include +#include +#include + +using namespace std; + +const int b = 32; + +int main() +{ + int v[b] = {0}; //tutti i valori sono uguali a 0 + char str[b]; + int valVuoto, i, j; + int num = 0; + + cin >> str; + /* se la lunghezza della stringa è inferiore a quella della base, indica da quale punto è vuota */ + if(strlen(str) < b) + valVuoto = strlen(str); + + /* ordina i valori in modo tale da spostarli a blocco, ovvero entrambi gli indici si incrementano + man mano che ordinano il vettore degli interi. La base - la prima X di 'str' è l'inizio dell'ordine + del vettore degli int. + + Seguendo questa logica e questo esempio: + STR - + 1 0 x x x x x x + + V - + x x x x x x 1 0 + */ + for(i = b - valVuoto, j = 0; i < b; i++, j++) + v[i] = str[j] - '0'; + + //il vettore viene letto in ordine decrescente, mentre le potenze in crescente + for(i = b - 1, j = 0; i > -1; i--, j++) + num += v[i] * pow(2, j); + + cout << num << endl; + + return 0; +} diff --git a/cpp/crittografia.cc b/cpp/crittografia.cc new file mode 100644 index 0000000..d448b86 --- /dev/null +++ b/cpp/crittografia.cc @@ -0,0 +1,89 @@ +#include +#include +#include +#include +#include + +using namespace std; + +void converti(char *str, int size); +void vocalic(char *str, int size); + +char consonantiMin[] = {'b','c','d','f','g','h','j','k','l','m','n','p','q','r','s','t','v','w','x','z'}; +char consonantiMax[] = {'B','C','D','F','G','H','J','K','L','M','N','P','Q','R','S','T','V','W','X','Z'}; + +int main() +{ + ifstream in; + ofstream out; + + in.open("input.txt"); + out.open("output.txt"); + + int N; + string ca; + + getline(in, ca); + istringstream(ca) >> N; + + for(int i = 0; i < N; i++){ + getline(in, ca); + char *c = new char[ca.length() + 1]; + strcpy(c, ca.c_str()); + converti(c, ca.length() + 1); + out << c << endl; + delete[] c; + } + + in.close(); + out.close(); + + return 0; +} + +void vocalic(char *str, int i) +{ + if(str[i] == 'a') str[i] = 'e'; + else if(str[i] == 'e') str[i] = 'i'; + else if(str[i] == 'i') str[i] = 'o'; + else if(str[i] == 'o') str[i] = 'u'; + else if(str[i] == 'u') str[i] = 'y'; + else if(str[i] == 'y') str[i] = 'a'; + else if(str[i] == 'A') str[i] = 'E'; + else if(str[i] == 'E') str[i] = 'I'; + else if(str[i] == 'I') str[i] = 'O'; + else if(str[i] == 'O') str[i] = 'U'; + else if(str[i] == 'U') str[i] = 'Y'; + else if(str[i] == 'Y') str[i] = 'A'; + else if(str[i] == 'z') str[i] = 'b'; + else if(str[i] == 'Z') str[i] = 'B'; + else if(str[i] == '0') str[i] = '1'; + else if(str[i] == '1') str[i] = '2'; + else if(str[i] == '2') str[i] = '3'; + else if(str[i] == '3') str[i] = '4'; + else if(str[i] == '4') str[i] = '5'; + else if(str[i] == '5') str[i] = '6'; + else if(str[i] == '6') str[i] = '7'; + else if(str[i] == '7') str[i] = '8'; + else if(str[i] == '8') str[i] = '9'; + else if(str[i] == '9') str[i] = '0'; +} + +void converti(char *str, int size) +{ + bool cpres = false; + for(int i = 0; i < size-1; i++){ + int s=1; + vocalic(str,i); + for(unsigned int j = 0; j < sizeof consonantiMin; j++){ + if(str[i] == consonantiMin[j] || str[i] == consonantiMax[j]){ + cpres = true; + if(str[i]+1 == 'A' || str[i]+1 == 'E' || str[i]+1 == 'I' || str[i]+1 == 'O' || str[i]+1 == 'U' || str[i]+1 == 'Y' || + str[i]+1 == 'a' || str[i]+1 == 'e' || str[i]+1 == 'i' || str[i]+1 == 'o' || str[i]+1 == 'u' || str[i]+1 == 'y') s = 2; + else s = 1; + } + } + if(cpres == true) str[i]+=s; + cpres = false; + } +} diff --git a/cpp/es4.cpp b/cpp/es4.cpp new file mode 100644 index 0000000..a1f1716 --- /dev/null +++ b/cpp/es4.cpp @@ -0,0 +1,67 @@ +#include +#define BIANCO 0 //Non Visitato +#define NERO 2 //Visitato +#define GRIGIO 1 //Non Finito +#define INF 999999 +#include +#include +#include +#define MAXN 9999 +#define INDEF -1 +#include +using namespace std; +typedef pair p; +int V,E; + +struct nodo { + vector

adj; + int dist; + nodo(){ + dist=INF; + } +}no[MAXN]; + int colore[MAXN]; + void relax (nodo no[], int u, int z) + { + p v= no[u].adj[z]; + if (no[v.first].dist> no[u].dist + v.second ) + { + no[v.first].dist= no[u].dist + v.second; + } + } + + void bf (nodo no[],int n, int s) + { + int i,j,z; + no[0].dist=0; + for (i=0;i>V>>E; + int a,b,c; + for (int i=0;i>a>>b>>c; + no[a].adj.push_back(p(b,c)); + } + bf(no,V,0); //Adiacenze, numeri di vertici, sorgente + for (int i=0;i +#define BIANCO 0 //Non Visitato +#define NERO 1 //Visitato +#define GRIGIO //Non Finito +#define INF 999999 +#include +#include +#include +#define MAXN 9999 +#define INDEF -1 +#include +using namespace std; +int V=9; //Nodi +int precedente[MAXN]; //Vettore su cui viene salvato il percorso per arrivare alla destinazione +struct nodo { + vector adj; +}no[MAXN];; + + int bfsVisit (int s) + { + int dist[V]; + int colore[V]; + queue q; + + for (int i=0;i sta; + int i=3; // arrivo + sta.push(i); + while (precedente[i]!=INDEF) + { + + } + */ //Procedura iterativa per stampare il percorso fino al nodo sorgente + + } + + void stampaPercorso (int j) //Procedura ricorsiva j=precedente[destinazione] + { + if (precedente[j] != INDEF ) + stampaPercorso(precedente[j]); + cout< + +using namespace std; + +static unsigned long int tot = 0; + +void hanoi(int d, int inizio, int fine, int transito) +{ + if (d == 1); + else { + hanoi(d - 1, inizio, transito, fine); + hanoi(d - 1, transito, fine, inizio); + } + tot++; +} + +int main() +{ + int dischi; + cout << "Numero dischi: "; + cin >> dischi; + + hanoi(dischi, 1, 3, 2); + cout << "In totale: " << tot << " mosse" << endl; + return 0; +} diff --git a/cpp/lswf.cpp b/cpp/lswf.cpp new file mode 100644 index 0000000..218a9c8 --- /dev/null +++ b/cpp/lswf.cpp @@ -0,0 +1,67 @@ +/* INPUT: + * 19 + * + * OUTPUT: + * 1000101 + */ +#include +#include +#define MAXG 1000 + +using namespace std; + +int fibonacci(int* fib, int N) +{ + fib[0] = 1; fib[1] = 1; + int lst; + + for(int i = 2; i < N; i++) { + fib[i] = fib[i-1] + fib[i-2]; + lst = i; + if(fib[i] > N) break; + } + + return lst; +} + +int main() +{ + ifstream in("input.txt"); + ofstream out("output.txt"); + + int N, i; + in >> N; + int caracts[MAXG], somma = 0, potSomma; + int lastc; + if(N > 4) + lastc = fibonacci(caracts, N); + else { + caracts[0] = 1; caracts[1] = 1; caracts[2] = 2; caracts[3] = 3; + if(N == 1) lastc = 1; + else if(N == 2) lastc = 2; + else if(N == 3) lastc = 3; + else lastc = 4; + } + int* seq = new int[lastc]; + +<<<<<<< HEAD + for(i = 0; i < lastc; i++) cout << caracts[i] << ' '; cout << endl; +======= + for(i = 0; i < lastc; i++) cout << caracts[i] << endl; cout << endl; +>>>>>>> devs + + seq[0] = 1; + for(i = lastc; i > 0; i--) { + potSomma = somma + caracts[i]; + if(potSomma < N) { + somma = potSomma; + seq[i] = 1; + } else seq[i] = 0; + } + for(i = 0; i < lastc; i++) out << seq[i]; + + delete[] seq; + in.close(); + out.close(); + return 0; +} diff --git a/cpp/numeri.cc b/cpp/numeri.cc new file mode 100644 index 0000000..ec2d2d4 --- /dev/null +++ b/cpp/numeri.cc @@ -0,0 +1,50 @@ +#include +#include + +using namespace std; + +int main(void) +{ + fstream file; + file.open("dati.dat"); + + typedef unsigned short int size_t; + + size_t a, b, c, seq = 0, tot = 0, num; + char stringa[] = "12312312312"; + char l; + while(true) + { + cout << "3 numeri: "; + cin >> a >> b >> c; + if(a >= 0 && a <= 9 && b >= 0 && b <= 9 && c >= 0 && c <= 9){ + if(a != b && b != c && a != c) break; + } + } + + file << a << endl; + file << b << endl; + file << c << endl; + file << stringa << endl; + file.seekg(5, file.beg); + + while(!file.eof()) + { + file.get(l); + num = l - '0'; + if(seq == 0) { + if(num == a) seq++; + } else if(seq == 1) { + if(num == b) seq++; + } else if(seq == 2) { + if(num == c) seq++; + } + + if(seq == 3) { tot++; seq = 0; } + } + + cout << "\n" << tot; + file.close(); + + return 0; +} diff --git a/cpp/palindromo.cc b/cpp/palindromo.cc new file mode 100644 index 0000000..1cb19a2 --- /dev/null +++ b/cpp/palindromo.cc @@ -0,0 +1,25 @@ +// ConsoleApplication1.cpp : definisce il punto di ingresso dell'applicazione console. +// +#include "stdafx.h" +#include + +using namespace std; + +bool palindromo(int i, int j, char str[]) +{ + if (i >= j) return true; + else if (str[i] == str[j]) return palindromo(i + 1, j - 1, str); + else return false; +} + +int main() +{ + char parola[] = "onorarono"; + + cout << ( (palindromo(0, sizeof parola - 2, parola) == 1) ? "E' palindromo" : "Non e' palindromo" ) << endl; + + cin.get(); + + return 0; +} + diff --git a/cpp/parentesi.cpp b/cpp/parentesi.cpp new file mode 100644 index 0000000..159b75f --- /dev/null +++ b/cpp/parentesi.cpp @@ -0,0 +1,58 @@ +/* INPUT: +[ ( ( [ { { [ ] ] ( ( ( } } ( ) ) ) ) ) ) ] ] ] + +output: +11 */ +#include +#include +#include + +using namespace std; + +int main() +{ + ifstream in; + ofstream out; + in.open("input.txt"); + out.open("output.txt"); + + int i; + int t = 0, q = 0, g = 0; //tonde, quadre, graffe + char str[1000], c; + i = 0; + while(!in.eof()) + { + in.get(c); + if(c == ' ') continue; + else { + str[i] = c; + i++; + } + } + + int n = strlen(str), tot = 0; + + for(int i = 0; i < n; i++) + { + if(str[i] == '(') t++; + else if(str[i] == '[') q++; + else if(str[i] == '{') g++; + + if(str[i] == ')' && t > 0) { + t--; + tot++; + } else if(str[i] == ']' && q > 0) { + q--; + tot++; + } else if(str[i] == '}' && g > 0) { + g--; + tot++; + } + } + + out << tot << endl; + + in.close(); + out.close(); + return 0; +} diff --git a/cpp/planet.cc b/cpp/planet.cc new file mode 100644 index 0000000..33cdea7 --- /dev/null +++ b/cpp/planet.cc @@ -0,0 +1,72 @@ +#include +#include +#include + +using namespace std; + +int main() +{ + ifstream in; + ofstream out; + in.open("input.txt"); + out.open("output.txt"); + + char ch; + string numero, val[2]; + int oraVuota = -1, giorno[96], i = 0, c = 0; + + for(int j = 0; j < 96; j++) giorno[j] = -1; + + getline(in, numero); + int N; + istringstream(numero) >> N; + + int ore[N][2]; + + while(!in.eof()) + { + in.get(ch); + + if(ch == '\n') { + val[0] = ""; + val[1] = ""; + i = 0; + c++; + + continue; + }else if(ch == ' '){ + i++; + }else { + val[i] += ch; + istringstream(val[i]) >> ore[c][i]; + } + + } + + i = 0; + while(i < N){ + if(ore[i][0] > ore[i][1]){ + for(int j = ore[i][0]; j < ore[i][1] || j < 96; j++) giorno[j] = 0; + for(int k = ore[i][1]-1; k >= 0; k--) giorno[k] = 0; + }else { + for(int k = ore[i][0]; k < ore[i][1]; k++) giorno[k] = 0; + } + i++; + } + + for(i = 0; i < 96; i++) { + if(giorno[i] == -1) { + oraVuota = i; + break; + } + + //cout << i << " " << giorno[i] << endl; + } + + out << oraVuota << endl; + + in.close(); + out.close(); + + return 0; +} diff --git a/cpp/scommesse.cpp b/cpp/scommesse.cpp new file mode 100644 index 0000000..2fa0936 --- /dev/null +++ b/cpp/scommesse.cpp @@ -0,0 +1,81 @@ +/* INPUT: + * 11 + * 1 0 2 6 4 5 3 9 8 10 7 + * + * OUTPUT: + * 2 + * 8 2 + */ +#include +#include +#include +#include + +using namespace std; + +vector carteOut; + +void cOutPresente(vector& kr, int x) +{ + bool s = false; + for(unsigned i = 0; i < kr.size(); i++) + if(kr[i] == x) s = true; + + if(!s) + kr.push_back(x); +} + +void fCarte(vector c, int N, int s) +{ + int i; + vector::iterator it; + vector::iterator start; + + while(c.size() > 1) { + //for(it = c.begin(); it != c.end(); it++) cout << *it << ' '; cout << endl; + int tot = c.size(); + for(i = s; i < tot-1; i++) { + if(!(((c[i] + c[i+1]) % 2) == 0)) { + start = c.begin()+i; + c.erase(start, start+2); + break; + } + } + + s = 0; + } + cOutPresente(carteOut, c[0]); +} + +int main() +{ + ifstream in("input.txt"); + ofstream out("output.txt"); + int N, i; + in >> N; + + int x; + vector carteV; + + for(i = 0; i < N; i++) { + in >> x; + carteV.push_back(x); + } + + for(int i = 0; i < 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::iterator ite = carteOut.begin(); ite != carteOut.end(); ite++) out << *ite << ' '; + + out.close(); + in.close(); + return 0; +} diff --git a/cpp/sorveglianza.c++ b/cpp/sorveglianza.c++ new file mode 100644 index 0000000..4154596 --- /dev/null +++ b/cpp/sorveglianza.c++ @@ -0,0 +1,88 @@ +/* INPUT: +10 +6 +2 5 +0 2 +1 3 +5 6 +4 7 +7 9 + +OUTPUT: +4*/ +#include +#include +#include + +using namespace std; + +int main(void) +{ + ifstream in; + ofstream out; + in.open("input.txt"); + out.open("output.txt"); + + int giorni, turniTot, i, j, tot = 0, m[2], x; + + in >> giorni; + in >> turniTot; + + vector< vector > turni(turniTot, vector(2)); + int* eDay = new int[giorni]; + + for(i = 0; i < giorni; i++) eDay[i] = 0; + + for(i = 0; i < turniTot; i++) + { + for(j = 0; j < 2; j++) + { + in >> x; + turni[i][j] = x; + } + } + + for(i = 0; i < turniTot-1; i++) + { + if(turni[i][0] > turni[i+1][0]) { + m[0] = turni[i][0]; + m[1] = turni[i][1]; + + turni[i][0] = turni[i+1][0]; + turni[i][1] = turni[i+1][1]; + + turni[i+1][0] = m[0]; + turni[i+1][1] = m[1]; + } + + if(turni[i][1] == giorni-1) { + m[0] = turni[i][0]; + m[1] = turni[i][1]; + + turni[i][0] = turni[i+1][0]; + turni[i][1] = turni[i+1][1]; + + turni[i+1][0] = m[0]; + turni[i+1][1] = m[1]; + } + } + + for(i = 0; i < turniTot-1; i++) + { + if(eDay[turni[i][0]] == 0) { + for(j = turni[i][0]; j <= turni[i][1]; j++) eDay[j] = 1; + tot++; + } else if(eDay[turni[i][1]] == 0 && turni[i][1] > turni[i+1][0]) { + for(j = turni[i][1]; j >= turni[i][0]; j--) eDay[j] = 1; + tot++; + } + } + + out << tot << endl; + + delete[] eDay; + in.close(); + out.close(); + + return 0; +} diff --git a/cpp/substring.cc b/cpp/substring.cc new file mode 100644 index 0000000..55aa319 --- /dev/null +++ b/cpp/substring.cc @@ -0,0 +1,22 @@ +#include + +using namespace std; + +void s(int i, int k, int n, char str[]); + +int main() +{ + char ss[] = "SANTO"; + s(0, 4, sizeof(ss), ss); + + return 0; +} + +void s(int i, int k, int n, char str[]) +{ + if(i < n - k){ + if(i < n-k) for(int j = i; j < i+k; j++) cout << str[j]; + cout << "\n"; + s(i+=1, k, n, str); + } +} diff --git a/crittografia.cc b/crittografia.cc deleted file mode 100644 index d448b86..0000000 --- a/crittografia.cc +++ /dev/null @@ -1,89 +0,0 @@ -#include -#include -#include -#include -#include - -using namespace std; - -void converti(char *str, int size); -void vocalic(char *str, int size); - -char consonantiMin[] = {'b','c','d','f','g','h','j','k','l','m','n','p','q','r','s','t','v','w','x','z'}; -char consonantiMax[] = {'B','C','D','F','G','H','J','K','L','M','N','P','Q','R','S','T','V','W','X','Z'}; - -int main() -{ - ifstream in; - ofstream out; - - in.open("input.txt"); - out.open("output.txt"); - - int N; - string ca; - - getline(in, ca); - istringstream(ca) >> N; - - for(int i = 0; i < N; i++){ - getline(in, ca); - char *c = new char[ca.length() + 1]; - strcpy(c, ca.c_str()); - converti(c, ca.length() + 1); - out << c << endl; - delete[] c; - } - - in.close(); - out.close(); - - return 0; -} - -void vocalic(char *str, int i) -{ - if(str[i] == 'a') str[i] = 'e'; - else if(str[i] == 'e') str[i] = 'i'; - else if(str[i] == 'i') str[i] = 'o'; - else if(str[i] == 'o') str[i] = 'u'; - else if(str[i] == 'u') str[i] = 'y'; - else if(str[i] == 'y') str[i] = 'a'; - else if(str[i] == 'A') str[i] = 'E'; - else if(str[i] == 'E') str[i] = 'I'; - else if(str[i] == 'I') str[i] = 'O'; - else if(str[i] == 'O') str[i] = 'U'; - else if(str[i] == 'U') str[i] = 'Y'; - else if(str[i] == 'Y') str[i] = 'A'; - else if(str[i] == 'z') str[i] = 'b'; - else if(str[i] == 'Z') str[i] = 'B'; - else if(str[i] == '0') str[i] = '1'; - else if(str[i] == '1') str[i] = '2'; - else if(str[i] == '2') str[i] = '3'; - else if(str[i] == '3') str[i] = '4'; - else if(str[i] == '4') str[i] = '5'; - else if(str[i] == '5') str[i] = '6'; - else if(str[i] == '6') str[i] = '7'; - else if(str[i] == '7') str[i] = '8'; - else if(str[i] == '8') str[i] = '9'; - else if(str[i] == '9') str[i] = '0'; -} - -void converti(char *str, int size) -{ - bool cpres = false; - for(int i = 0; i < size-1; i++){ - int s=1; - vocalic(str,i); - for(unsigned int j = 0; j < sizeof consonantiMin; j++){ - if(str[i] == consonantiMin[j] || str[i] == consonantiMax[j]){ - cpres = true; - if(str[i]+1 == 'A' || str[i]+1 == 'E' || str[i]+1 == 'I' || str[i]+1 == 'O' || str[i]+1 == 'U' || str[i]+1 == 'Y' || - str[i]+1 == 'a' || str[i]+1 == 'e' || str[i]+1 == 'i' || str[i]+1 == 'o' || str[i]+1 == 'u' || str[i]+1 == 'y') s = 2; - else s = 1; - } - } - if(cpres == true) str[i]+=s; - cpres = false; - } -} diff --git a/es4.cpp b/es4.cpp deleted file mode 100644 index a1f1716..0000000 --- a/es4.cpp +++ /dev/null @@ -1,67 +0,0 @@ -#include -#define BIANCO 0 //Non Visitato -#define NERO 2 //Visitato -#define GRIGIO 1 //Non Finito -#define INF 999999 -#include -#include -#include -#define MAXN 9999 -#define INDEF -1 -#include -using namespace std; -typedef pair p; -int V,E; - -struct nodo { - vector

adj; - int dist; - nodo(){ - dist=INF; - } -}no[MAXN]; - int colore[MAXN]; - void relax (nodo no[], int u, int z) - { - p v= no[u].adj[z]; - if (no[v.first].dist> no[u].dist + v.second ) - { - no[v.first].dist= no[u].dist + v.second; - } - } - - void bf (nodo no[],int n, int s) - { - int i,j,z; - no[0].dist=0; - for (i=0;i>V>>E; - int a,b,c; - for (int i=0;i>a>>b>>c; - no[a].adj.push_back(p(b,c)); - } - bf(no,V,0); //Adiacenze, numeri di vertici, sorgente - for (int i=0;i -#define BIANCO 0 //Non Visitato -#define NERO 1 //Visitato -#define GRIGIO //Non Finito -#define INF 999999 -#include -#include -#include -#define MAXN 9999 -#define INDEF -1 -#include -using namespace std; -int V=9; //Nodi -int precedente[MAXN]; //Vettore su cui viene salvato il percorso per arrivare alla destinazione -struct nodo { - vector adj; -}no[MAXN];; - - int bfsVisit (int s) - { - int dist[V]; - int colore[V]; - queue q; - - for (int i=0;i sta; - int i=3; // arrivo - sta.push(i); - while (precedente[i]!=INDEF) - { - - } - */ //Procedura iterativa per stampare il percorso fino al nodo sorgente - - } - - void stampaPercorso (int j) //Procedura ricorsiva j=precedente[destinazione] - { - if (precedente[j] != INDEF ) - stampaPercorso(precedente[j]); - cout< - -using namespace std; - -static unsigned long int tot = 0; - -void hanoi(int d, int inizio, int fine, int transito) -{ - if (d == 1); - else { - hanoi(d - 1, inizio, transito, fine); - hanoi(d - 1, transito, fine, inizio); - } - tot++; -} - -int main() -{ - int dischi; - cout << "Numero dischi: "; - cin >> dischi; - - hanoi(dischi, 1, 3, 2); - cout << "In totale: " << tot << " mosse" << endl; - return 0; -} diff --git a/lswf.cpp b/lswf.cpp deleted file mode 100644 index 218a9c8..0000000 --- a/lswf.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/* INPUT: - * 19 - * - * OUTPUT: - * 1000101 - */ -#include -#include -#define MAXG 1000 - -using namespace std; - -int fibonacci(int* fib, int N) -{ - fib[0] = 1; fib[1] = 1; - int lst; - - for(int i = 2; i < N; i++) { - fib[i] = fib[i-1] + fib[i-2]; - lst = i; - if(fib[i] > N) break; - } - - return lst; -} - -int main() -{ - ifstream in("input.txt"); - ofstream out("output.txt"); - - int N, i; - in >> N; - int caracts[MAXG], somma = 0, potSomma; - int lastc; - if(N > 4) - lastc = fibonacci(caracts, N); - else { - caracts[0] = 1; caracts[1] = 1; caracts[2] = 2; caracts[3] = 3; - if(N == 1) lastc = 1; - else if(N == 2) lastc = 2; - else if(N == 3) lastc = 3; - else lastc = 4; - } - int* seq = new int[lastc]; - -<<<<<<< HEAD - for(i = 0; i < lastc; i++) cout << caracts[i] << ' '; cout << endl; -======= - for(i = 0; i < lastc; i++) cout << caracts[i] << endl; cout << endl; ->>>>>>> devs - - seq[0] = 1; - for(i = lastc; i > 0; i--) { - potSomma = somma + caracts[i]; - if(potSomma < N) { - somma = potSomma; - seq[i] = 1; - } else seq[i] = 0; - } - for(i = 0; i < lastc; i++) out << seq[i]; - - delete[] seq; - in.close(); - out.close(); - return 0; -} diff --git a/numeri.cc b/numeri.cc deleted file mode 100644 index ec2d2d4..0000000 --- a/numeri.cc +++ /dev/null @@ -1,50 +0,0 @@ -#include -#include - -using namespace std; - -int main(void) -{ - fstream file; - file.open("dati.dat"); - - typedef unsigned short int size_t; - - size_t a, b, c, seq = 0, tot = 0, num; - char stringa[] = "12312312312"; - char l; - while(true) - { - cout << "3 numeri: "; - cin >> a >> b >> c; - if(a >= 0 && a <= 9 && b >= 0 && b <= 9 && c >= 0 && c <= 9){ - if(a != b && b != c && a != c) break; - } - } - - file << a << endl; - file << b << endl; - file << c << endl; - file << stringa << endl; - file.seekg(5, file.beg); - - while(!file.eof()) - { - file.get(l); - num = l - '0'; - if(seq == 0) { - if(num == a) seq++; - } else if(seq == 1) { - if(num == b) seq++; - } else if(seq == 2) { - if(num == c) seq++; - } - - if(seq == 3) { tot++; seq = 0; } - } - - cout << "\n" << tot; - file.close(); - - return 0; -} diff --git a/palindromo.cc b/palindromo.cc deleted file mode 100644 index 1cb19a2..0000000 --- a/palindromo.cc +++ /dev/null @@ -1,25 +0,0 @@ -// ConsoleApplication1.cpp : definisce il punto di ingresso dell'applicazione console. -// -#include "stdafx.h" -#include - -using namespace std; - -bool palindromo(int i, int j, char str[]) -{ - if (i >= j) return true; - else if (str[i] == str[j]) return palindromo(i + 1, j - 1, str); - else return false; -} - -int main() -{ - char parola[] = "onorarono"; - - cout << ( (palindromo(0, sizeof parola - 2, parola) == 1) ? "E' palindromo" : "Non e' palindromo" ) << endl; - - cin.get(); - - return 0; -} - diff --git a/parentesi.cpp b/parentesi.cpp deleted file mode 100644 index 159b75f..0000000 --- a/parentesi.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/* INPUT: -[ ( ( [ { { [ ] ] ( ( ( } } ( ) ) ) ) ) ) ] ] ] - -output: -11 */ -#include -#include -#include - -using namespace std; - -int main() -{ - ifstream in; - ofstream out; - in.open("input.txt"); - out.open("output.txt"); - - int i; - int t = 0, q = 0, g = 0; //tonde, quadre, graffe - char str[1000], c; - i = 0; - while(!in.eof()) - { - in.get(c); - if(c == ' ') continue; - else { - str[i] = c; - i++; - } - } - - int n = strlen(str), tot = 0; - - for(int i = 0; i < n; i++) - { - if(str[i] == '(') t++; - else if(str[i] == '[') q++; - else if(str[i] == '{') g++; - - if(str[i] == ')' && t > 0) { - t--; - tot++; - } else if(str[i] == ']' && q > 0) { - q--; - tot++; - } else if(str[i] == '}' && g > 0) { - g--; - tot++; - } - } - - out << tot << endl; - - in.close(); - out.close(); - return 0; -} diff --git a/planet.cc b/planet.cc deleted file mode 100644 index 33cdea7..0000000 --- a/planet.cc +++ /dev/null @@ -1,72 +0,0 @@ -#include -#include -#include - -using namespace std; - -int main() -{ - ifstream in; - ofstream out; - in.open("input.txt"); - out.open("output.txt"); - - char ch; - string numero, val[2]; - int oraVuota = -1, giorno[96], i = 0, c = 0; - - for(int j = 0; j < 96; j++) giorno[j] = -1; - - getline(in, numero); - int N; - istringstream(numero) >> N; - - int ore[N][2]; - - while(!in.eof()) - { - in.get(ch); - - if(ch == '\n') { - val[0] = ""; - val[1] = ""; - i = 0; - c++; - - continue; - }else if(ch == ' '){ - i++; - }else { - val[i] += ch; - istringstream(val[i]) >> ore[c][i]; - } - - } - - i = 0; - while(i < N){ - if(ore[i][0] > ore[i][1]){ - for(int j = ore[i][0]; j < ore[i][1] || j < 96; j++) giorno[j] = 0; - for(int k = ore[i][1]-1; k >= 0; k--) giorno[k] = 0; - }else { - for(int k = ore[i][0]; k < ore[i][1]; k++) giorno[k] = 0; - } - i++; - } - - for(i = 0; i < 96; i++) { - if(giorno[i] == -1) { - oraVuota = i; - break; - } - - //cout << i << " " << giorno[i] << endl; - } - - out << oraVuota << endl; - - in.close(); - out.close(); - - return 0; -} diff --git a/scommesse.cpp b/scommesse.cpp deleted file mode 100644 index 2fa0936..0000000 --- a/scommesse.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/* INPUT: - * 11 - * 1 0 2 6 4 5 3 9 8 10 7 - * - * OUTPUT: - * 2 - * 8 2 - */ -#include -#include -#include -#include - -using namespace std; - -vector carteOut; - -void cOutPresente(vector& kr, int x) -{ - bool s = false; - for(unsigned i = 0; i < kr.size(); i++) - if(kr[i] == x) s = true; - - if(!s) - kr.push_back(x); -} - -void fCarte(vector c, int N, int s) -{ - int i; - vector::iterator it; - vector::iterator start; - - while(c.size() > 1) { - //for(it = c.begin(); it != c.end(); it++) cout << *it << ' '; cout << endl; - int tot = c.size(); - for(i = s; i < tot-1; i++) { - if(!(((c[i] + c[i+1]) % 2) == 0)) { - start = c.begin()+i; - c.erase(start, start+2); - break; - } - } - - s = 0; - } - cOutPresente(carteOut, c[0]); -} - -int main() -{ - ifstream in("input.txt"); - ofstream out("output.txt"); - int N, i; - in >> N; - - int x; - vector carteV; - - for(i = 0; i < N; i++) { - in >> x; - carteV.push_back(x); - } - - for(int i = 0; i < 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::iterator ite = carteOut.begin(); ite != carteOut.end(); ite++) out << *ite << ' '; - - out.close(); - in.close(); - return 0; -} diff --git a/sorveglianza.c++ b/sorveglianza.c++ deleted file mode 100644 index 4154596..0000000 --- a/sorveglianza.c++ +++ /dev/null @@ -1,88 +0,0 @@ -/* INPUT: -10 -6 -2 5 -0 2 -1 3 -5 6 -4 7 -7 9 - -OUTPUT: -4*/ -#include -#include -#include - -using namespace std; - -int main(void) -{ - ifstream in; - ofstream out; - in.open("input.txt"); - out.open("output.txt"); - - int giorni, turniTot, i, j, tot = 0, m[2], x; - - in >> giorni; - in >> turniTot; - - vector< vector > turni(turniTot, vector(2)); - int* eDay = new int[giorni]; - - for(i = 0; i < giorni; i++) eDay[i] = 0; - - for(i = 0; i < turniTot; i++) - { - for(j = 0; j < 2; j++) - { - in >> x; - turni[i][j] = x; - } - } - - for(i = 0; i < turniTot-1; i++) - { - if(turni[i][0] > turni[i+1][0]) { - m[0] = turni[i][0]; - m[1] = turni[i][1]; - - turni[i][0] = turni[i+1][0]; - turni[i][1] = turni[i+1][1]; - - turni[i+1][0] = m[0]; - turni[i+1][1] = m[1]; - } - - if(turni[i][1] == giorni-1) { - m[0] = turni[i][0]; - m[1] = turni[i][1]; - - turni[i][0] = turni[i+1][0]; - turni[i][1] = turni[i+1][1]; - - turni[i+1][0] = m[0]; - turni[i+1][1] = m[1]; - } - } - - for(i = 0; i < turniTot-1; i++) - { - if(eDay[turni[i][0]] == 0) { - for(j = turni[i][0]; j <= turni[i][1]; j++) eDay[j] = 1; - tot++; - } else if(eDay[turni[i][1]] == 0 && turni[i][1] > turni[i+1][0]) { - for(j = turni[i][1]; j >= turni[i][0]; j--) eDay[j] = 1; - tot++; - } - } - - out << tot << endl; - - delete[] eDay; - in.close(); - out.close(); - - return 0; -} diff --git a/substring.cc b/substring.cc deleted file mode 100644 index 55aa319..0000000 --- a/substring.cc +++ /dev/null @@ -1,22 +0,0 @@ -#include - -using namespace std; - -void s(int i, int k, int n, char str[]); - -int main() -{ - char ss[] = "SANTO"; - s(0, 4, sizeof(ss), ss); - - return 0; -} - -void s(int i, int k, int n, char str[]) -{ - if(i < n - k){ - if(i < n-k) for(int j = i; j < i+k; j++) cout << str[j]; - cout << "\n"; - s(i+=1, k, n, str); - } -} -- cgit v1.2.3-18-g5258