0% found this document useful (0 votes)
134 views86 pages

Eccpr Passed

The document discusses 6 coding problems involving arrays, strings, loops, and mathematical functions in C++. Problem 1 involves counting words that start and end with given letters and are within given length ranges. Problem 2 decodes 7-segment display patterns. Problem 3 calculates arrangements of distinct products. Problem 4 enhances image contrast by filtering pixel values. Problem 5 filters words from a string. Problem 6 determines if numbers in an array are prime.

Uploaded by

Radu Necula
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
134 views86 pages

Eccpr Passed

The document discusses 6 coding problems involving arrays, strings, loops, and mathematical functions in C++. Problem 1 involves counting words that start and end with given letters and are within given length ranges. Problem 2 decodes 7-segment display patterns. Problem 3 calculates arrangements of distinct products. Problem 4 enhances image contrast by filtering pixel values. Problem 5 filters words from a string. Problem 6 determines if numbers in an array are prime.

Uploaded by

Radu Necula
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 86

1. Problema 0.

1 - Jocul literelor

#include<iostream>

#include<string>

#include<sstream>

#include<cstring>

using namespace std;

int main() {

char alfa;

char beta;

int m,n,i=0,j=0;

char propozitie[10000];

string cuvinte[10000];

// strlwr -> caracter cu dimensiune

// strlen(c) -> caracter normal

// str.length() -> sir de caractere

cin>>alfa>>beta>>m>>n;

cin.get();

cin.get(propozitie,10000);

// strlwr(propozitie);

for(int i = 0; propozitie[i]; i++){

propozitie[i] = tolower(propozitie[i]);

for(int i = 0; i < strlen(propozitie); i++){

if(propozitie[i] == ' ') {


j++;

else {

cuvinte[j] = cuvinte[j] + propozitie[i];

j = j +1;

int conditia_1 = 0;

int conditia_2 = 0;

int conditia_3 = 0;

for(int i = 0; i < j; i++){

if(cuvinte[i][0] == tolower(alfa) && cuvinte[i][cuvinte[i].length()-1] == tolower(beta) &&


cuvinte[i].length() < m) {

conditia_1++;

if(cuvinte[i][0] == tolower(alfa) && cuvinte[i][cuvinte[i].length()-1] == tolower(beta) &&


cuvinte[i].length() >= m && cuvinte[i].length() < n) {

conditia_2++;

if(cuvinte[i][0] == tolower(alfa) && cuvinte[i][cuvinte[i].length()-1] == tolower(beta) &&


cuvinte[i].length() >= n) {

conditia_3++;

cout<<conditia_1<<' '<<conditia_2<<' '<<conditia_3<<endl;


}

1. Problema 0.2 - Afișaj șapte segmente

#include<iostream>

#include<string>

using namespace std;

int main() {

string linie;

char punct;

while(!cin.eof()) {

getline(cin,linie);

if(linie == "") break;

punct = linie[linie.length()-1]; // Aici e punctul

linie.erase(linie.length() - 2); // Scoate ultima cifra si virgula de la final

if(punct != '0' && punct != '1') break;

if( linie=="0,1,1,0,0,0,0") cout<< 1;

else if( linie== "1,1,0,1,1,0,1") cout<< 2;

else if( linie== "1,1,1,1,0,0,1") cout<< 3;

else if( linie== "0,1,1,0,0,1,1") cout<< 4;

else if( linie== "1,0,1,1,0,1,1") cout<< 5;

else if( linie== "1,0,1,1,1,1,1") cout<< 6;

else if( linie== "1,1,1,0,0,0,0") cout<< 7;

else if( linie== "1,1,1,1,1,1,1") cout<< 8;

else if( linie== "1,1,1,1,0,1,1") cout<< 9;

else if( linie== "1,1,1,1,1,1,0") cout<< 0;

else break;
if(punct == '1') cout<<'.';

1. Problema 1 - Aranjamente produse

#include<iostream>

using namespace std;

long double factorial(long double n)

if (n > 1)

return n * factorial(n - 1);

else

return 1;

int main () {

long double k,m;

long double aranjamente;

cin>>k>>m;

long double n = k;

aranjamente = factorial(n)/(factorial(n-k));

while(aranjamente <= m) {

n++;

aranjamente = factorial(n)/(factorial(n-k));

}
if( n == k) {

cout<<0<<endl;

else {

cout<<n-1<<endl;

1. Problema 2 - Îmbunătăţire contrast

#include<iostream>

#include <iomanip>

using namespace std;

int main() {

int m,n,j,i,x;

cin>>m;

cin>>n;

int a[m][n];

for(i =0; i < m; i++){

for(j = 0; j < n; j++) {

cin>>a[i][j];

// Teste de afisare

// for(i =0; i < m; i++){

// for(j = 0; j < n; j++) {


// cout<<a[i][j]<<' ';

// }

// cout<<endl;

// }

int filtrat[m][n];

for(i =0; i < m; i++){

for(j = 0; j < n; j++) {

filtrat[i][j] = int(a[i][j]*0.9 + 2);

// Teste de afisare

// for(i =0; i < m; i++){

// for(j = 0; j < n; j++) {

// cout<<filtrat[i][j]<<' ';

// }

// cout<<endl;

// }

//

int diferenta[m][n];

for(i =0; i < m; i++){

for(j = 0; j < n; j++) {

diferenta[i][j] = filtrat[i][j] - a[i][j];

// Teste de afisare

// for(i =0; i < m; i++){


// for(j = 0; j < n; j++) {

// cout<<diferenta[i][j]<<' ';

// }

// cout<<endl;

// }

float medie;

float suma = 0;

for(i =0; i < m; i++){

for(j = 0; j < n; j++) {

suma += diferenta[i][j];

medie = suma/(m*n);

cout << fixed << setprecision(2) << medie; //Afisare cu 2 zecimale cu aproximare

// Teste de afisare

// x = int(3*0.9 + 2); // Partea intreaga

// cout<<x;

1. Problema 3 - Filtru cuvinte

#include<iostream>

#include<string>

#include<cstring>

using namespace std;

int main() {
int n;

char propozitie[10000];

cin.get(propozitie,10000);

cin>>n;

string cuvinte[n];

for(int i = 0; i < n; i++){

cin>>cuvinte[i];

// Test

// for(int i = 0; i < strlen(propozitie); i++){

// cout<<propozitie[i];

// }

string propozitie_noua;

for(int i = 0; i < strlen(propozitie); i++){

propozitie_noua += propozitie[i];

// Test

// cout<<propozitie_noua;

string propozitie_inlocuita;

for(int i = 0; i < n; i++){

string de_cautat = cuvinte[i];

int pozitie = propozitie_noua.find(de_cautat);

//cout<<pozitie<<endl;

// Apeleaza pana cand nu se mai gaseste

while(pozitie >= 0) {

string stelute;

for(int j = 0; j < de_cautat.length(); j++) stelute = stelute + "*";

// Test
//cout<<cuvinte[i]<<" "<<stelute<<endl;

propozitie_inlocuita = propozitie_noua.replace(pozitie,
de_cautat.length(),stelute);

de_cautat = cuvinte[i];

pozitie = propozitie_noua.find(de_cautat);

// Teste

//string stelute;

//for(int j = 0; j < de_cautat.length(); j++) stelute = stelute + "*";

//cout<<cuvinte[i]<<" "<<stelute<<endl;

//string propozitie2 = propozitie_noua.replace(pozitie, de_cautat.length(),"*******");

// Teste

// string str1 = "agresiv";

// int pozitie = propozitie_noua.find("agresiv");

// cout<<pozitie;

// string propozitie2 = propozitie_noua.replace(76,str1.length(),"*******");

cout<<propozitie_inlocuita<<endl;

1. Problema 4 - Imagini prime

#include<iostream>

using namespace std;

int main() {
int m,n,j,i,d,nr,numar;

cin>>m;

cin>>n;

int initial[m][n];

for(i=0; i<m; i++){

for(j=0; j<n; j++) {

cin>>initial[i][j];

int binar[m][n];

for(i=0; i<m; i++){

for(j=0; j<n; j++) {

if(initial[i][j] == 0 || initial[i][j] == 1){

binar[i][j] = 1;

else {

// Algoritm determinare numar prim

nr = 0;

numar = initial[i][j];

for(d=2;d<=numar/2;d++) {

if(numar%d==0) nr++;

if(nr==0) binar[i][j] = 0;

else binar[i][j] = 1;

}
}

int obiecte = 0;

for(i=0; i<m; i++){

for(j=0; j<n; j++) {

if(binar[i][j] == 1) {

obiecte++;

cout<<obiecte<<'\n';

1. Problema 5 - Combinări rezistoare

#include<iostream>

using namespace std;

long double factorial(long double n)

if (n > 1)

return n * factorial(n - 1);

else

return 1;

int main () {

long double n,m;

long double combinari;

cin>>n>>m;
long double k = 0;

int gasit = 0;

combinari = factorial(n)/(factorial(k)*factorial(n-k));

while(k <= n) {

k++;

combinari = factorial(n)/(factorial(k)*factorial(n-k));

if(combinari >= m) {

gasit = 1;

break;

if(gasit == 0) cout<<0<<endl;

else cout<<k<<endl;

1. Problema 6 - Valori reprezentative

#include<iostream>

#include<iomanip>

using namespace std;

int main() {

int v1,v2;

cin>>v1;

int vector1[v1];

for(int i = 0; i < v1; i++){

cin>>vector1[i];

}
cin>>v2;

int vector2[v2];

for(int i = 0; i < v2; i++){

cin>>vector2[i];

// Teste

// for(int i = 0; i < v1; i++){

// cout<<vector1[i]<<' ';

// }

// cout<<endl;

// for(int i = 0; i < v2; i++){

// cout<<vector2[i]<<' ';

// }

int l = v1+v2;

int vector_con[l];

for(int i = 0; i < v1; i++){

vector_con[i] = vector1[i];

for(int i = 0; i < v2; i++){

vector_con[v1+i] = vector2[i];

// Teste

// for(int i = 0; i < l; i++){

// cout<<vector_con[i]<<' ';

// }
int counter;

int valori_rep[1000];

int k = 0;

int auxiliar = 0;

for(int i = 0; i < l; i++){

auxiliar = vector_con[i];

counter = 0;

for(int i = 0; i < l; i++) {

if(auxiliar >= vector_con[i]) {

counter++;

if(counter > 5){

valori_rep[k] = auxiliar;

k++;

float medie;

float suma;

for(int i = 0; i < k; i++){

suma += valori_rep[i];

medie = suma/k;

cout<<fixed<<setprecision(2)<<medie;

}
1. Problema 8 - Maximele semnalului

#include<iostream>

using namespace std;

int main() {

int n;

cin>>n;

float v[n];

for(int i = 0; i < n; i++){

cin>>v[i];

float valori_maxime[200];

int z = 0;

for(int i = 0; i < n; i++){

if(i == 0) {

if(v[i] > v[i+1]){

valori_maxime[z] = v[i];

z++;

else if(i == n-1){

if(v[i] > v[i-1]){

valori_maxime[z] = v[i];

z++;

}
}

else {

if(v[i] > v[i+1] && v[i] > v[i-1]) {

valori_maxime[z] = v[i];

z++;

// cout<<z;

//

// for(int i = 0; i < z; i++){

// cout<<valori_maxime[i]<<' ';

// }

float suma = 0;

float medie;

for(int i = 0; i < z; i++){

suma = suma + valori_maxime[i];

medie = suma / z;

int counter = 0;

for(int i = 0; i < n; i++){

if(v[i] > medie) {

counter++;

}
}

cout<<counter;

1. Problema 9 - Campionat de fotbal

#include<iostream>

#include<string>

#include<cstring>

#include<algorithm>

using namespace std;

struct Meci {

string linie_meci;

string vector_linie[100];

string echipa_a;

string echipa_d;

int goluri_a;

int goluri_d;

};

struct Echipa {

string nume;

int goluri;

int puncte;

int goluri_p;

};
bool compare (string a, string b) {return a < b;}

bool compare_struct (Echipa a, Echipa d) {return a.puncte > d.puncte;}

int main() {

int n,k;

cin>>n;// Numar echipe

cin>>k;// Numar meciuri

Meci meci[k];

Echipa echipa[n];

cin.get();

for(int i = 0; i < k; i++) {

getline(cin,meci[i].linie_meci);

for(int i = 0; i < k; i++) {

int x = 0;

for(int j = 0; j < meci[i].linie_meci.length(); j++) {

if(meci[i].linie_meci[j] == ' ') {

x++;

else {

meci[i].vector_linie[x] += meci[i].linie_meci[j];

}
// for(int i = 0; i < k; i++){

// for(int j = 0; j < 5; j++) {

// cout<<j<<" : "<<meci[i].vector_linie[j]<<endl;

// }

// cout<<endl;

// }

for(int i = 0; i < k; i++){

meci[i].echipa_a = meci[i].vector_linie[0];

meci[i].goluri_a = stoi(meci[i].vector_linie[1]);

meci[i].echipa_d = meci[i].vector_linie[4];

meci[i].goluri_d = stoi(meci[i].vector_linie[3]);

string nume_echipa[10000];

int counter_echipa = 0;

for(int i = 0; i < k; i++){

nume_echipa[counter_echipa] = meci[i].vector_linie[0];

counter_echipa++;

nume_echipa[counter_echipa] = meci[i].vector_linie[4];

counter_echipa++;

sort(nume_echipa, nume_echipa+counter_echipa, compare);

string echipe_unice[10000];

int z = 0;

// for(int j = 0; j < counter_echipa; j++) {

// if(j % (k/2) == 0) {echipe_unice[z] = nume_echipa[j]; z++;}

// }

int u = 0;

for(int j = 0; j < counter_echipa; j++) {


int gasit = 0;

for(int x = 0; x < j; x++) {

if(nume_echipa[j] == nume_echipa[x]){

gasit = 1;

if(gasit == 0) {

echipe_unice[u] = nume_echipa[j];

u++;

// for(int j = 0; j < u; j++) {

// cout<<echipe_unice[j]<<endl;

// }

//cout<<u<<endl;

for(int j = 0; j < u; j++) {

echipa[j].nume = echipe_unice[j];

for(int i = 0; i < k; i++){

if(meci[i].goluri_a == meci[i].goluri_d) {

for(int j = 0; j < u; j++) {

if(meci[i].echipa_a == echipa[j].nume) {

echipa[j].puncte += 1;

echipa[j].goluri += meci[i].goluri_a;

echipa[j].goluri_p += meci[i].goluri_d;

if(meci[i].echipa_d == echipa[j].nume) {
echipa[j].puncte += 1;

echipa[j].goluri += meci[i].goluri_d;

echipa[j].goluri_p += meci[i].goluri_a;

if(meci[i].goluri_a > meci[i].goluri_d) {

for(int j = 0; j < u; j++) {

if(meci[i].echipa_a == echipa[j].nume) {

echipa[j].puncte += 3;

echipa[j].goluri += meci[i].goluri_a;

echipa[j].goluri_p += meci[i].goluri_d;

if(meci[i].echipa_d == echipa[j].nume) {

echipa[j].puncte += 0;

echipa[j].goluri += meci[i].goluri_d;

echipa[j].goluri_p += meci[i].goluri_a;

if(meci[i].goluri_a < meci[i].goluri_d) {

for(int j = 0; j < u; j++) {

if(meci[i].echipa_a == echipa[j].nume) {

echipa[j].puncte += 0;

echipa[j].goluri += meci[i].goluri_a;

echipa[j].goluri_p += meci[i].goluri_d;

if(meci[i].echipa_d == echipa[j].nume) {
echipa[j].puncte += 3;

echipa[j].goluri += meci[i].goluri_d;

echipa[j].goluri_p += meci[i].goluri_a;

sort(echipa, echipa+u, compare_struct);

for(int j = 0; j < u; j++) {

cout<<echipa[j].nume<<" "<<echipa[j].puncte<<" "<<echipa[j].goluri<<" "<<echipa[j].goluri_p<<endl;

1. Problema 10 - Secvenţe lungi de numere mari

#include<iostream>

using namespace std;

int main() {

int n;

cin>>n;

float vector_initial[n];

for(int i = 0; i < n; i++){

cin>>vector_initial[i];

float prag;

cin>>prag;
float vector_prelucrat[n];

for(int i = 0; i < n; i++){

if(vector_initial[i] > prag) {

vector_prelucrat[i] = 1;

else {

vector_prelucrat[i] = 0;

int secventa = 0;

for(int i = 0; i < n; i++){

if(vector_prelucrat[i] == 1) {

if(vector_prelucrat[i+1] == 0) {

secventa++;

else if(i+1 == n) {

secventa++;

cout<<secventa<<endl;

1. Problema 11 - Cifru de substituţie

#include<iostream>
#include<string>

#include<sstream>

#include<cstring>

using namespace std;

int main() {

char propozitie[10000];

char string_inlocuit[100000];

string cuvinte[10000];

cin.get(propozitie,10000);

cin.get();

cin.get(string_inlocuit,100000);

char aux;

int j=0;

for(int i = 0; i < strlen(string_inlocuit); i++){

if(string_inlocuit[i] == ' ') {

j++;

else {

cuvinte[j] = cuvinte[j] + string_inlocuit[i];

j = j +1;

for(int i = 0; i < strlen(propozitie); i++) {

aux = propozitie[i];
for( int x=0;x< j;x++) {

if(aux == cuvinte[x][0]) {

propozitie[i] = cuvinte[x][2];

for(int i = 0; i<strlen(propozitie); i++) {

cout<<propozitie[i];

cout<<endl;

1. Problema 12 - Supermarket

#include<iostream>

using namespace std;

struct Database {

string code;

char name;

float price;

} database[10000];

struct Code {

string code;

} code[10000];

int main() {
int b,n;

float total_price = 0;

float discount = 0;

cin>>b>>n;

for(int i = 0; i < b; i++) {

cin>>database[i].code>>database[i].name>>database[i].price;

// Teste

// for(int i = 0; i < b; i++) {

// cout<<database[i].code<<' '<<database[i].name<<' '<<database[i].price;

// }

for(int i = 0; i < n; i++) {

cin>>code[i].code;

// Teste

// cout<<endl;

// for(int i = 0; i < n; i++) {

// cout<<code[i].code<<' ';

// }

for(int i = 0; i < n; i++) {

for(int j = 0; j < b; j++) {

if(code[i].code == database[j].code) {

if(database[j].name == 'p') {

total_price += database[j].price;

if(database[j].name == 'c') {
discount += database[j].price;

float price_with_discount = 0;

if(discount > 0) {

price_with_discount = total_price - total_price * (discount/100);

cout<<price_with_discount<<endl;

else {

cout<<total_price<<endl;

1. Problema 2.3 - Cod binar

#include<iostream>

using namespace std;

int main() {

int n;

cin>>n;

int v[n];

int a[n][8];

int binaryNum[1000];

for(int i = 0; i <n; i++ ) {

cin>>v[i];
}

for(int i = 0; i<n; i++) {

for(int j = 0; j<8;j++) {

a[i][j] = 0;

// for(int i = 0; i<n; i++) {

// for(int j = 0; j<8;j++) {

// cout<<a[i][j]<<' ';

// }

// cout<<endl;

// }

int k = 0;

for(int i = 0; i<n; i++) {

int m = v[k];

int z = 0;

while (m > 0) {

// Tine restul in vector

a[i][z] = m % 2;

m = m / 2;

z++;

k++;

// Valori binare afisare

// for(int i = 0; i<n; i++) {


// for (int j = 8 - 1; j >= 0; j--) {

// cout<<a[i][j]<<' ';

// }

// cout<<endl;

// }

int suma_linilor[n];

int x = 0;

for(int i = 0; i<n; i++) {

int suma = 0;

for(int j = 0; j<8;j++) {

suma +=a[i][j];

suma_linilor[x] = suma;

x++;

// for (int i = 0; i < x; i++) {

//

// cout<<suma_linilor[i]<<' ';

// }

int minim = suma_linilor[0];

// cout<<minim<<endl;

for (int i = 1; i < x; i++) {

if (minim > suma_linilor[i]) {

minim = suma_linilor[i];

}
// cout<<minim<<endl;

int minime[10000];

minime[0] = minim; //Just in case

int index = 0;

for (int i = 0; i < x; i++) {

if(minim == suma_linilor[i]) {

minime[index] = i;

index++;

//teste

// for(int i =0; i < index; i++) {

// cout<<minime[i]<<endl;

// }

//

for(int i = 0; i < index; i++) {

cout<<v[minime[i]]<<endl;

1. Problema 2.5 - Cea mai mare formă geometrică

#include<iostream>

#include<iomanip>

using namespace std;

struct Patrat {
string nume;

float latura;

float arie;

}patrate[1000];

struct Dreptunghi {

string nume;

float latura_unu;

float latura_doi;

float arie;

}dreptunghiuri[1000];

struct Cerc {

string nume;

float raza;

float arie;

}cercuri[1000];

int main() {

float latura;

string nume;

float mere;

int n;

cin>>n;

int p = 0,d = 0,c = 0;

for(int i = 0; i < n; i++) {

cin>>nume;
if(nume == "patrat") {

cin>>latura;

patrate[p].latura = latura;

patrate[p].nume = "patrat";

p++;

if(nume == "dreptunghi") {

cin>>dreptunghiuri[d].latura_unu>>dreptunghiuri[d].latura_doi;

dreptunghiuri[d].nume = "dreptunghi";

d++;

if(nume == "cerc") {

cin>>cercuri[c].raza;

cercuri[c].nume = "cerc";

c++;

float vector_arie[10000];

// string nume_figuri[10000];

float arie_patrat = 1;

int index = 0;

for(int j =0; j < p; j++) {

arie_patrat = patrate[j].latura * patrate[j].latura;

patrate[j].arie = arie_patrat;

vector_arie[index] = arie_patrat;

// nume_figuri[index] = "patrat";

index++;

}
float arie_dreptunghi = 1;

for(int j = 0; j < d; j++) {

arie_dreptunghi = dreptunghiuri[j].latura_doi * dreptunghiuri[j].latura_unu;

dreptunghiuri[j].arie = arie_dreptunghi;

vector_arie[index] = arie_dreptunghi;

// nume_figuri[index] = "dreptunghi";

index++;

float arie_cerc = 1;

for(int j = 0; j < c; j++) {

arie_cerc = cercuri[j].raza * cercuri[j].raza * 3.14;

cercuri[j].arie = arie_cerc;

vector_arie[index] = arie_cerc;

// nume_figuri[index] = "cerc";

index++;

float maxim = 0;

int pozitie;

for(int i = 0; i < index; i++ ) {

if(vector_arie[i] > maxim) {

maxim = vector_arie[i];

pozitie = i;

// cout<<vector_arie[i];

}
//Teste

// cout<<fixed<<setprecision(2)<<maxim<<' '<<nume_figuri[pozitie];

// Nu merge fara setprecision chiar daca primeste acelasi lucru de la tastatura din cauza ca nu salveaza
3.90 ci 3.9 variabila de tip float

for(int j =0; j < p; j++) {

if(patrate[j].arie == maxim) {

cout<<patrate[j].nume<<' '<<fixed<<setprecision(2)<<patrate[j].latura<<endl;

for(int j = 0; j < d; j++) {

if(dreptunghiuri[j].arie == maxim) {

cout<<dreptunghiuri[j].nume<<'
'<<fixed<<setprecision(2)<<dreptunghiuri[j].latura_unu<<'
'<<fixed<<setprecision(2)<<dreptunghiuri[j].latura_doi<<endl;

for(int j = 0; j < c; j++) {

if(cercuri[j].arie == maxim) {

cout<<cercuri[j].nume<<' '<<fixed<<setprecision(2)<<cercuri[j].raza<<endl;

}
1. Problema 2.6 - Cel mai mare dreptunghi

#include<iostream>

using namespace std;

struct Dreptunghi {

string nume;

int x1;

int x2;

int y1;

int y2;

int arie;

}dreptunghiuri[10000];

int main() {

int n;

cin>>n;

for(int i = 0; i < n; i++) {

cin>>dreptunghiuri[i].nume>>dreptunghiuri[i].x1>>dreptunghiuri[i].y1>>dreptunghiuri[i].x2>>dr
eptunghiuri[i].y2;

for(int i = 0; i < n; i++) {

dreptunghiuri[i].arie = (dreptunghiuri[i].x2 - dreptunghiuri[i].x1) * (dreptunghiuri[i].y2 -


dreptunghiuri[i].y1);

}
//TEST

// for(int i = 0; i < n; i++) {

// cout<<dreptunghiuri[i].nume<<' '<<dreptunghiuri[i].x1<<' '<<dreptunghiuri[i].y1<<'


'<<dreptunghiuri[i].x2<<' '<<dreptunghiuri[i].y2<<' '<<dreptunghiuri[i].arie<<endl;

//

// }

int maxim_arie = 0;

for(int i = 0; i < n; i++) {

if(dreptunghiuri[i].arie > maxim_arie) {

maxim_arie = dreptunghiuri[i].arie;

for(int i = 0; i < n; i++) {

if( dreptunghiuri[i].arie == maxim_arie){

cout<<dreptunghiuri[i].nume<<' '<<dreptunghiuri[i].x1<<'
'<<dreptunghiuri[i].y1<<' '<<dreptunghiuri[i].x2<<' '<<dreptunghiuri[i].y2<<'
'<<dreptunghiuri[i].arie<<endl;

1. Problema 3.1 - Bucket list

#include<iostream>
using namespace std;

int main() {

long long int n;

long long int


v1[100000],v2[100000],v3[100000],v4[100000],v5[100000],v6[100000],v7[100000],v8[100000],v9[1000
00],v10[100000],v11[100000],v12[100000],v13[100000],v14[100000],v15[100000],v16[100000],v17[100
000],v18[100000],v19[100000];

long long int values[100000];

cin>>n;

for(int i = 0; i < n ; i++) {

cin>>values[i];

long long int i1 = 0,i2 = 0,i3 = 0,i4 = 0,i5 = 0,i6 = 0,i7 = 0,i8 = 0,i9 = 0,i10 = 0,i11 = 0,i12 = 0,i13 =
0,i14 = 0,i15 = 0,i16 = 0,i17 = 0,i18 = 0,i19 = 0;

for(int i = 0; i < n ; i++) {

if(values[i] >= 0 && values[i] <= 9 ) {

v1[i1] = values[i];

i1++;

if(values[i] >= 10 && values[i] <= 99 ) {

v1[i2] = values[i];

i2++;

if(values[i] >= 100 && values[i] <= 999 ) {

v1[i3] = values[i];

i3++;
}

if(values[i] >= 1000 && values[i] <= 9999 ) {

v1[i4] = values[i];

i4++;

if(values[i] >= 10000 && values[i] <= 99999 ) {

v1[i5] = values[i];

i5++;

if(values[i] >= 100000 && values[i] <= 999999 ) {

v1[i6] = values[i];

i6++;

if(values[i] >= 1000000 && values[i] <= 9999999 ) {

v1[i7] = values[i];

i7++;

if(values[i] >= 10000000 && values[i] <= 99999999 ) {

v1[i8] = values[i];

i8++;

if(values[i] >= 100000000 && values[i] <= 999999999 ) {

v1[i9] = values[i];

i9++;

if(values[i] >= 1000000000 && values[i] <= 9999999999 ) {

v1[i10] = values[i];

i10++;

}
if(values[i] >= 10000000000 && values[i] <= 99999999999 ) {

v1[i11] = values[i];

i11++;

if(values[i] >= 100000000000 && values[i] <= 999999999999 ) {

v1[i12] = values[i];

i12++;

if(values[i] >= 1000000000000 && values[i] <= 9999999999999 ) {

v1[i13] = values[i];

i13++;

if(values[i] >= 10000000000000 && values[i] <= 99999999999999 ) {

v1[i14] = values[i];

i14++;

if(values[i] >= 100000000000000 && values[i] <= 999999999999999 ) {

v1[i15] = values[i];

i15++;

if(values[i] >= 1000000000000000 && values[i] <= 9999999999999999 ) {

v1[i16] = values[i];

i16++;

if(values[i] >= 10000000000000000 && values[i] <= 99999999999999999 ) {

v1[i17] = values[i];

i17++;

if(values[i] >= 100000000000000000 && values[i] <= 999999999999999999 ) {


v1[i18] = values[i];

i18++;

if(values[i] >= 100000000000000000 && values[i] <= 999999999999999999 ) {

v1[i19] = values[i];

i19++;

if(i1 != 0) cout<<1<<' '<<i1<<endl;

if(i2 != 0) cout<<2<<' '<<i2<<endl;

if(i3 != 0) cout<<3<<' '<<i3<<endl;

if(i4 != 0) cout<<4<<' '<<i4<<endl;

if(i5 != 0) cout<<5<<' '<<i5<<endl;

if(i6 != 0) cout<<6<<' '<<i6<<endl;

if(i7 != 0) cout<<7<<' '<<i7<<endl;

if(i8 != 0) cout<<8<<' '<<i8<<endl;

if(i9 != 0) cout<<9<<' '<<i9<<endl;

if(i10 != 0) cout<<10<<' '<<i10<<endl;

if(i11 != 0) cout<<11<<' '<<i11<<endl;

if(i12 != 0) cout<<12<<' '<<i12<<endl;

if(i13 != 0) cout<<13<<' '<<i13<<endl;

if(i14 != 0) cout<<14<<' '<<i14<<endl;

if(i15 != 0) cout<<15<<' '<<i15<<endl;

if(i16 != 0) cout<<16<<' '<<i16<<endl;

if(i17 != 0) cout<<17<<' '<<i17<<endl;

if(i18 != 0) cout<<18<<' '<<i18<<endl;

if(i19 != 0) cout<<19<<' '<<i19<<endl;


//cout<<i1<<' '<<i2<<' '<<i3<<' '<<i4<<' '<<i5<<' '<<i6<<' '<<i7<<' '<<i8<<' '<<i9<<' '<<i10<<'
'<<i11<<' '<<i12<<' '<<i13<<' '<<i14<<' '<<i15<<' '<<i16<<' '<<i17<<' '<<i18<<' '<<i19;

//
cout<<i1<<endl<<i2<<endl<<i3<<endl<<i4<<endl<<i5<<endl<<i6<<endl<<i7<<endl<<i8<<endl<<i
9<<endl<<i10<<endl<<i11<<endl<<i12<<endl<<i13<<endl<<i14<<endl<<i15<<endl<<i16<<endl<<i17<<e
ndl<<i18<<endl<<i19;

1. Problema 3.2 - Controlor de trafic

#include<iostream>

#include<string>

using namespace std;

int main()

int n;

int i = 0;

int autobuz;

int autobuze[10000];

cin>>n;

while(cin >> autobuz){

autobuze[i] = autobuz;

i++;

// for(int j = 0; j < i; j++) {

// cout<<autobuze[j]<<endl;
// }

int autobuze_ordine[n];

// for(int j = 1; j <=n; j++) {

// autobuze_ordine[j] = j;

// }

int x = 1;

int counter = 0;

while(x <= n) {

autobuze_ordine[counter] = x;

counter++;

x++;

// for(int j = 0; j < n; j++) {

// cout<<autobuze_ordine[j]<<endl;

// }

int aux;

int statii_unice[10000];

int b = 0;

for(int j = 0; j < n; j++) {

aux = autobuze_ordine[j];

int cnt = 0;

for(int e = 0; e < i; e++) {

if(aux == autobuze[e]) {

cnt++;

// cout<<cnt<<endl;

}
if(cnt == 0) {

statii_unice[b] = aux;

b++;

// cout<<b;

int suma = 0;

for(int j = 0; j < b; j++) {

suma += statii_unice[j];

// cout<<statii_unice[j];

cout<<suma<<endl;

1. Problema 3.3 - Forme geometrice regulate

#include<iostream>

#include<math.h>

using namespace std;

int main() {

int n;

cin>>n;

float vx[10000];

float vy[10000];
for(int i = 0; i < n; i++) {

cin>>vx[i]>>vy[i];

// Test

// for(int i = 0; i < n; i++) {

// cout<<vx[i]<<' '<<vy[i]<<endl;

// }

float laturi[n];

int counter = 0;

for(int i = 0; i < n; i++) {

float temp = 0;

float dif_x;

float dif_y;

if(i+1 < n) {

dif_x = vx[i] - vx[i+1];

dif_y = vy[i] - vy[i+1];

temp = sqrt(dif_x*dif_x + dif_y*dif_y);

laturi[counter] = temp;

counter++;

else {

dif_x = vx[n-1] - vx[0];

dif_y = vy[n-1] - vy[0];

temp = sqrt(dif_x*dif_x + dif_y*dif_y);

laturi[counter] = temp;

counter++;

}
for(int i =0; i < n; i++) cout<<laturi[i]<<' ';

int counter1 = 0;

for(int i = 0; i < n; i++) {

float aux = laturi[0];

// Comparatie absoluta pentru numere float

bool comparatie = fabs(aux-laturi[i]) < laturi[i] * .001;

if(!comparatie) {

counter1++;

if(counter1 == 0) cout<<"da"<<endl;

else cout<<"nu"<<endl;

1. Problema 3.5 - Statistică valori

#include<iostream>

#include<math.h>

using namespace std;

int main() {

int n,m;

cin>>n;

cin>>m;

int a[n][m];

float h[m*n];
for(int i = 0; i < n; i++) {

for(int j = 0; j < m; j++) {

cin>>a[i][j];

int index = 0;

int valori_matrice[m*n];

int k =0;

for(int i = 0; i < n; i++) {

for(int j = 0; j < m; j++) {

valori_matrice[k] = a[i][j];

k++;

// test

// for(int i = 0; i<m*n; i++) {

// cout<<valori_matrice[i]<<" ";

// }

cout<<endl;

float medie = 0;

for(int x = 0; x <=9; x++) {

int counter = 0;

for(int i = 0; i < m*n; i++) {

if(x == valori_matrice[i]) {

counter++;

h[index] = counter;
index++;

float suma = 0;

float d = 0;

for(int i = 0; i<=9; i++) {

suma += h[i];

medie = suma/10;

float suma_h = 0;

for(int i = 0; i<=9; i++) {

suma_h += (h[i]-medie)*(h[i]-medie);

d = sqrt(suma_h/10);

int counter1 = 0;

for(int i = 0; i<=9; i++) {

if(h[i] >= d) {

counter1++;

cout<<counter1<<endl;

1. Problema 3.7 - Bingo

#include<iostream>

using namespace std;


int main() {

int n,k;

cin>>n>>k;

int bunica[n*n];

int strigat[k];

for(int i = 0; i < n*n; i++) {

cin>>bunica[i];

for(int i = 0; i < k; i++) {

cin>>strigat[i];

// TESTE

// for(int i = 0; i < n*n; i++) {

// cout<<bunica[i]<<' ';

// }

//

// cout<<endl;

//

// for(int i = 0; i < k; i++) {

// cout<<strigat[i]<<' ';

// }

// cout<<endl;

int ramase[10000];

int counter = 0;
int citite = 0;

for(int j = 0; j < n*n; j++) {

int auxiliar = bunica[j];

int nr_strigat = 0;

for(int i = 0; i < k; i++) {

if(auxiliar == strigat[i]) {

nr_strigat++;

if(nr_strigat == 0) {

ramase[counter] = auxiliar;

counter++;

else {

citite++;

if(citite == n*n) {

cout<<"BINGO!"<<endl;

else {

cout<<counter<<endl;

1. Problema 3.8 - Load balancing

#include<iostream>

using namespace std;


int main (){

int k,n,j,counter,coloane;

cin>>k>>n;

int pachete[n];

for(int i = 0; i < n; i++) {

cin>>pachete[i];

int a[k][10000] = {0};

// Teste

// for(int i = 0; i < n; i++) {

// cout<<pachete[i]<<" ";

// }

if(k >= n) {

for(int i = 0; i < n; i++) {

cout<<pachete[i]<<endl;

else {

int j = 0, y =0, pachet = 0;

while(j < n){

for(int x = 0; x < k; x++){

a[x][y] = pachete[pachet];

pachet++; // Posibil ca la ultima iteratie int pachet sa treaca peste


numarul de pachete in for asa ca daca ajunge egal cu n iesim din for

if(pachet == n) break;

j = j + k;
y++;

for(int i = 0; i < k; i++){

for(int j = 0; j < y; j++) {

if(a[i][j] != 0) cout<<a[i][j]<<' ';

cout<<endl;

1. Problema 4.1 - Zile de naștere

#include<iostream>

#include<string>

#include<algorithm>

using namespace std;

struct Date {

string linie;

};

struct dateUnice {

string linie;

string zi;
string luna;

};

bool compare (dateUnice a, dateUnice b) {

if(a.luna == b.luna) {

return a.zi < b.zi;

else {

return a.luna < b.luna;

int main() {

int n;

cin>>n;

struct Date data[n];

for(int i = 0; i < n; i++) {

cin>>data[i].linie;

// for(int i = 0; i < n; i++) {

// cout<<data[i].linie<<endl;

// }

string date_unice[10000];

int u = 0;

for(int j = 0; j < n; j++) {

int gasit = 0;

for(int x = 0; x < j; x++) {

if(data[j].linie== data[x].linie){
gasit = 1;

if(gasit == 0) {

date_unice[u] = data[j].linie;

u++;

dateUnice unice[u];

for(int i = 0; i < u; i++) {

unice[i].linie = date_unice[i];

unice[i].zi = date_unice[i].erase(2,3);

unice[i].luna = (unice[i].linie).erase(0,3);

sort(unice,unice+u,compare);

for(int i = 0; i < u; i++) {

cout<<unice[i].zi<<"-"<<unice[i].luna<<endl;

1. Problema 4.4 - Codare semnal imagine (Image Encoding)

#include<iostream>

using namespace std;

//bool compare(int a, int b) {

// return a < b;

//}
int main() {

int m,n;

//int a[m][n];

cin>>m;

cin>>n;

int v[m*n];

for(int i = 0; i < m*n; i++) {

cin>>v[i];

// for(int i = 0; i < m*n; i++) {

// cout<<v[i]<<" ";

// }

int u = 0;

int v_unice[1000];

for(int j = 0; j < m*n; j++) {

int gasit = 0;

for(int x = 0; x < j; x++) {

if(v[j]== v[x]){

gasit = 1;

if(gasit == 0) {

v_unice[u] = v[j];

u++;

}
// cout<<endl;

// for(int i = 0; i < u; i++) {

// cout<<v_unice[i]<<" ";

// }

int diferenta = (m*n) - (u *2);

cout<<diferenta<<endl;

1. Problema 4.7 - Rezistența nominală

#include<iostream>

#include<math.h>

#include<iomanip>

using namespace std;

int main() {

int n;

cin>>n;

float v[n];

for(int i = 0; i < n; i++) {

cin>>v[i];

// Teste

// for(int i = 0; i < n; i++) {

// cout<<v[i]<<" ";

// }
float medie;

float suma = 0;

for(int i = 0; i < n; i++) {

suma += v[i];

medie = suma/n;

float suma_2 = 0;

float dispersie;

for(int i = 0; i < n; i++) {

suma_2 += (v[i] - medie) * (v[i] - medie);

dispersie = sqrt(suma_2/n);

float counter = 0;

for(int i = 0; i < n; i++) {

if(v[i] >= (medie-dispersie) && v[i] <= (medie+dispersie)) {

counter++;

float total = counter*100/n;

cout<<fixed<<setprecision(2)<<total<<endl;

1. Problema 4.8 - Triunghiuri


#include<iostream>

#include<math.h>

#include<iomanip>

using namespace std;

struct Triunghiuri {

float a;

float b;

float c;

int tip;

float suprafata;

float perimetru;

float raport;

}triunghi[10000];

bool check_echilateral(float a, float b, float c) {

if(a == b && b == c ) return true;

else return false;

bool check_dreptunghic(float a, float b, float c) {

if((a*a == b*b + c*c) || (b*b == c*c + a*a) || (c*c == a*a + b*b)) return true;
else return false;

bool check_isoscel(float a, float b, float c) {

if((a == b) || (b == c) || (a == c)) return true;

else return false;

bool check_triunghi (float a, float b, float c) {

if( a < b + c && b < a + c && c < a + b) return true;

else return false;

int main() {

int n;

cin>>n;

for(int i = 0; i < n; i++) {

cin>>triunghi[i].a>>triunghi[i].b>>triunghi[i].c;
}

// Stabilim tipul triunghiurilor 0 - nu e triunghi, 1 - oarecare, 2 -


echilateral,dreptunghic sau isoscel

for(int i = 0; i < n; i++) {

if(check_triunghi(triunghi[i].a, triunghi[i].b, triunghi[i].c)) {

triunghi[i].tip = 1;

if(check_dreptunghic(triunghi[i].a, triunghi[i].b, triunghi[i].c) ||


check_isoscel(triunghi[i].a, triunghi[i].b, triunghi[i].c) || check_echilateral(triunghi[i].a,
triunghi[i].b, triunghi[i].c)) {

triunghi[i].tip = 2;

else {

triunghi[i].tip = 0;

float s;

// Aflam perimetrul, suprafata si raportul suprafata/perimetru doar pentru


triunghiurile oarecare

for(int i = 0; i < n; i++) {

if(triunghi[i].tip == 1) {

triunghi[i].perimetru = triunghi[i].a + triunghi[i].b + triunghi[i].c;


s = (triunghi[i].a + triunghi[i].b + triunghi[i].c)/2;

triunghi[i].suprafata = sqrt(s*(s-triunghi[i].a )*(s-triunghi[i].b)*(s-


triunghi[i].c));

triunghi[i].raport = triunghi[i].suprafata/triunghi[i].perimetru;

// Afla maximul dintre triunghiurile oarecare si memoreaza pozitia

float max = 0;

int index;

for(int i = 0; i < n; i++) {

if(triunghi[i].tip == 1) {

if(triunghi[i].raport > max) {

max = triunghi[i].raport;

index = i;

// Setare precizie de 3 zecimale

cout<<index<<" "<<fixed<<setprecision(3)<<max;

// Teste

// cout<<check_dreptunghic(3.0, 4.0,5.0)<<endl;
// cout<<check_isoscel(3.0, 3.0,5.0)<<endl;

// cout<<check_echilateral(6.0, 6.0, 6.0)<<endl;

1. Problema 4.10 - Mașini de curse

#include<iostream>

using namespace std;

struct Masini {

float pozitie;

float viteza;

float timp;

}masina[1000];

int main (){

int distanta,n;

cin>>distanta>>n;

for(int i = 0; i < n; i++) {

cin>>masina[i].pozitie>>masina[i].viteza;
}

// Test afisare

// for(int i =0; i < n; i++) {

// cout<<masina[i].pozitie<<" "<<masina[i].viteza<<endl;

// }

// Timpul pentru fiecare masina salvat in structura

for(int i =0; i < n; i++) {

masina[i].timp = (distanta - masina[i].pozitie)/masina[i].viteza;

// Timpul minim

float minim = masina[0].timp;

for(int i = 0; i < n; i++) {

if(masina[i].timp < minim) minim = masina[i].timp;

// Afisare valori

for(int i =0; i < n; i++) {

if(masina[i].timp == minim) cout<<i+1<<" ";


}

cout<<endl;

1. Problema 4.13 - Probă de rezistenţă

#include<iostream>

#include<algorithm>

using namespace std;

struct Student {

string nume;

string prenume;

int timp;

};

// Functie pentru sortare struct -- pentru sortare crescatoare <

// Pentru sortare descrescatoare >

// Implementare sort(student, student+n, student_compare); n - numarul de


elemente din struct

bool student_compare(Student student1, Student student2) { return student1.timp <


student2.timp; }

int main() {

int n;
int barem;

cin>>n;

Student student[n];

for(int i = 0; i < n; i++) {

cin>>student[i].nume>>student[i].prenume>>student[i].timp;

cin>>barem;

// Teste

// cout<<endl;

//

// for(int i = 0; i < n; i++) {

// cout<<student[i].nume<<" "<<student[i].prenume<<"
"<<student[i].timp<<endl;

// }

int counter = 0;

for(int i = 0; i < n; i++) {

if(student[i].timp <= barem) {

counter++;

}
if(counter == 0) {

cout<<0<<endl;

else {

// Sortare structura dupa camp

sort(student, student+n, student_compare);

cout<<counter<<endl;

for(int i = 0; i < counter; i++) {

cout<<student[i].nume<<" "<<student[i].prenume<<"
"<<student[i].timp<<endl;

1. Problema 5.8 - Criptanaliză

#include<iostream>

#include<algorithm>

using namespace std;

bool compare (int a, int b) { return a<b; }

int main() {
int n; // Numere

int k; // Prag

int nr; // Numarator

int numar; // Numar de testat

cin>>n>>k;

int v[n];

int numere_prime[10000];

for(int i = 0; i < n; i++) {

cin>>v[i];

int x = 0;

for(int i = 0; i < n; i++) {

if(v[i] == 1) {

numere_prime[x] = v[i];

x++;

else {

nr = 0;

numar = v[i];

for(int d = 2; d <= numar/2; d++) {

if(numar % d == 0) nr++;

}
if(nr == 0) {

numere_prime[x] = v[i];

x++;

// Vector nesortat

// for(int i = 0; i < x; i++) {

// cout<<numere_prime[i]<<endl;

// }

sort(numere_prime, numere_prime+x, compare);

// Vector sortat

// for(int i = 0; i < x; i++) {

// cout<<numere_prime[i]<<endl;

// }

int gasit = 0;

int valoare_gasita;

for(int i = 0; i < x; i++) {

if(numere_prime[i] >= k) {

valoare_gasita = numere_prime[i];

gasit = 1;

break;
}

if(gasit == 0) {

cout<<-1<<endl;

else {

cout<<valoare_gasita<<endl;

1. 2018.1.2 - Distribuție biți RNG

#include<iostream>

#include<string>

#include<algorithm>

#include<iomanip>

using namespace std;

struct Aparitie {

string nume;

float apr;

};
bool compare (Aparitie a, Aparitie b){

return a.apr < b.apr;

int main() {

int n;

cin>>n;

char serie[n];

string propozitie;

string vector_cuvinte[10001];

for(int i = 0; i < n; i++){

cin>>serie[i];

// for(int i = 0; i < n; i++){

// cout<<serie[i];

// }

for(int i = 0; i < n; i++){

propozitie += serie[i];

int cnt = 0;
for(int i = 0; i < n; i++){

if(i % 2 != 0) {

vector_cuvinte[cnt] += serie[i];

else {

cnt++;

vector_cuvinte[cnt] += serie[i];

cnt = cnt+1;

// for(int i = 0; i < cnt; i++){

// cout<<vector_cuvinte[i]<<" ";

// }

string posibile[4];

posibile[0] = "10";

posibile[1] = "11";

posibile[2] = "00";

posibile[3] = "01";
int aparitii[10000];

int index = 0;

for(int i = 0; i < 4; i++){

string de_cautat = posibile[i];

int counter = 0;

for(int j = 0; j < cnt; j++) {

if(posibile[i] == vector_cuvinte[j]) {

counter++;

aparitii[index] = counter;

index++;

// cout<<index;

Aparitie ap[index];

for(int i = 0; i < index; i++){

ap[i].nume = posibile[i];

ap[i].apr = aparitii[i];

}
float counter_de_1 = 0;

for(int i = 0; i < propozitie.length(); i++){

if(propozitie[i] == '1') {

counter_de_1++;

float counter_de_0 = propozitie.length() - counter_de_1;

// cout<<endl;

sort(ap, ap+index, compare);

// for(int i = 0; i < index; i++){

// cout<<ap[i].nume<<" : "<<ap[i].apr<<endl;

// }

// cout<<endl;

// cout<<ap[index-1].apr<<endl;

// cout<<ap[0].apr<<endl;

float raport1 = ap[index-1].apr / ap[0].apr;

float raport2 = 0;

if(counter_de_0 >= counter_de_1) raport2 = counter_de_0/counter_de_1;

else raport2 = counter_de_1/counter_de_0;


cout<<fixed<<setprecision(2)<<raport1<<"
"<<fixed<<setprecision(2)<<raport2<<endl;

if(raport1 <= 1.10 && raport2 <= 1.10) cout<<1;

else cout<<0;

// cout<<endl;

// cout<<"0 : "<<counter_de_0<<endl;

// cout<<"1 : "<<counter_de_1<<endl;

1. 2018.1.3 - Loturi de componente electronice

#include<iostream>

#include<algorithm>

using namespace std;

struct Lot {

int numar;

string linie;

char componente[120];

int condensatoare;

int rezistoare;

int tranzistoare;
bool util;

};

bool compare(Lot a, Lot b) {

return a.numar < b.numar;

int main() {

int n;

int k;

cin>>n;

Lot lot[n];

int x = 0;

while(x < n) {

cin>>k;

lot[x].numar = k;

for(int i = 0; i < k; i++) {

cin>>lot[x].componente[i];

x++;

}
// for(int i = 0; i < n; i++) {

// cout<<lot[i].numar<<endl;

// for(int j = 0; j < lot[i].numar; j++) {

// cout<<lot[i].componente[j]<<" ";

// }

// }

for(int i = 0; i < n; i++) {

for(int j = 0; j < lot[i].numar; j++) {

lot[i].linie += lot[i].componente[j];

for(int i = 0; i < n; i++) {

int r = 0, c = 0, t = 0;

for(int j = 0; j < (lot[i].linie).length(); j++) {

if(lot[i].linie[j] == 'R') {

r++;

else if(lot[i].linie[j] == 'C') {

c++;
}

else if(lot[i].linie[j] == 'T') {

t++;

lot[i].rezistoare = r;

lot[i].condensatoare = c;

lot[i].tranzistoare = t;

if(c >= t && r>=c && r>0 && c>0 && t>0) {

lot[i].util = 1;

else {

lot[i].util = 0;

// cout<<lot[0].rezistoare<<endl;

// cout<<lot[0].tranzistoare<<endl;

// cout<<lot[0].condensatoare<<endl;

sort(lot, lot+n, compare);

int counter_utile = 0;
for(int i = 0; i < n; i++) {

if(lot[i].util) {

counter_utile+=1;

cout<<counter_utile<<" "<<lot[n-1].numar<<endl;

1. 2018.1.4 - Cinematograf

#include<iostream>

#include<algorithm>

using namespace std;

struct Film {

string linie;

string titlu;

string linie_v[3];

string timp;

string ora;

string minute;
long int diferenta;

int pret;

};

bool compare (Film a, Film b) {

if(a.ora == b.ora) {

return a.minute < b.minute;

else {

return a.ora < b.ora;

bool compare_after_dif(Film a, Film b) {

if(a.diferenta == b.diferenta) {

return a.pret < b.pret;

else {

return a.diferenta < b.diferenta;

}
}

int main(){

string ora_i;

int n;

cin>>ora_i;

cin>>n;

Film filme[n];

cin.get();

for(int i = 0; i < n; i++) {

getline(cin,filme[i].linie);

// for(int i = 0; i < n; i++) {

// cout<<filme[i].linie<<endl;

// }

for(int i = 0; i < n; i++) {

int counter = 0;

for(int j = 0; j < filme[i].linie.length(); j++) {

if(filme[i].linie[j] == ' ') {

counter++;
}

else {

filme[i].linie_v[counter] += filme[i].linie[j];

// for(int i = 0; i < n; i++) {

// for(int j = 0; j < 3; j++) {

// cout<<j<<" "<<filme[i].linie_v[j]<<" ";

// }

// cout<<endl;

// }

for(int i = 0; i < n; i++) {

filme[i].timp = filme[i].linie_v[0];

filme[i].pret = stoi(filme[i].linie_v[1]);

filme[i].titlu = filme[i].linie_v[2];

string aux3 = ora_i;


string aux4 = ora_i;

string ora_i_ora = aux3.erase(2,3);

string ora_i_minute = aux4.erase(0,3);

for(int i = 0; i < n; i++) {

string aux = filme[i].timp;

string aux2 = filme[i].timp;

filme[i].ora = aux.erase(2,3);

filme[i].minute = aux2.erase(0,3);

if(stoi(filme[i].ora) < stoi(ora_i_ora)) {

filme[i].diferenta = 240*60;

else if(stoi(filme[i].ora) <= stoi(ora_i_ora)) {

if(stoi(filme[i].minute) < stoi(ora_i_minute))

filme[i].diferenta = 240*60;

else {

filme[i].diferenta = abs(stoi(filme[i].ora) - stoi(ora_i_ora))*60 +


abs(stoi(filme[i].minute) - stoi(ora_i_minute));

else {

if(stoi(filme[i].minute) >= stoi(ora_i_minute))


filme[i].diferenta = abs(stoi(filme[i].ora) -stoi(ora_i_ora))*60 +
abs(stoi(filme[i].minute) - stoi(ora_i_minute));

else

filme[i].diferenta = abs(stoi(filme[i].ora) -stoi(ora_i_ora))*60 -


abs(stoi(filme[i].minute) - stoi(ora_i_minute));

sort(filme, filme+n,compare_after_dif);

cout<<filme[0].titlu<<endl;

1. 2018.1.5 - Casino

#include<iostream>

using namespace std;

// struct Carte {

// int numar;

// string culoare;
// };

struct Carte {

string nume;

};

int main() {

int n;

cin>>n;

Carte carti[n];

cin.get();

for(int i = 0; i < n ; i++) {

getline(cin,carti[i].nume);

// for(int i = 0; i < n ; i++) {

// cout<<carti[i].nume<<endl;

// }

// cout<<endl;

string unice[n];
int counter = 0;

for(int i = 0; i < n ; i++) {

int gasit = 0;

for(int j = 0; j < i; j++) {

if(carti[i].nume == carti[j].nume && carti[i].nume != " "){

gasit = 1;

if(gasit == 0) {

if(carti[i].nume != " ") {

unice[counter] = carti[i].nume;

counter++;

// cout<<endl;

// for(int i = 0; i < counter ; i++) {

// cout<<unice[i]<<endl;

// }

int v[counter];

int index = 0;
for(int i = 0; i < counter ; i++) {

int cnt = 0;

for(int j = 0; j < n; j++) {

if(unice[i] == carti[j].nume && unice[i] != " ") {

cnt++;

v[index] = cnt;

index++;

// cout<<endl;

// for(int i = 0; i < index ; i++) {

// cout<<unice[i]<<" "<<v[i]<<endl;

// }

int gasit2 = 0;

for(int i = 0; i < index ; i++) {

if(v[i] >= 3) {

gasit2 = 1;

cout<<unice[i]<<endl;

break;

}
if(gasit2 == 0) cout<<"JOC OK"<<endl;

You might also like