-
Notifications
You must be signed in to change notification settings - Fork 3
/
1045_Seminar02.cpp
63 lines (53 loc) · 1.14 KB
/
1045_Seminar02.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include<iostream>
#include<string>
using namespace std;
int pozitieCuvantLung(string* v, int n) {
int max = 0;
for (int i = 1; i < n; i++) {
if (v[i].length() > v[max].length()) {
max = i;
}
}
return max;
}
void stergemDePeOPozitie(string* &v, int &n, int poz) {
string*aux = new string[n - 1];
int j = 0;
for (int i = 0; i < n; i++) {
if (i != poz) {
aux[j++] = v[i];
}
}
delete[]v;
v = aux;
n--;
}
void stergereElementLung(string* &v, int &n) {
//determinam pozitia celui mai lung cuvant
int pozitie = pozitieCuvantLung(v, n);
//stergem elementul de pe acea pozitie si scadem n;
stergemDePeOPozitie(v, n, pozitie);
}
void main() {
string sir = "semar 2";
sir = "Seminar 2";
sir.append("-pointeri");
cout << sir << endl;
cout << sir.substr(sir.find('-')+1, 8)<<endl;
string vector[20];
int n = 4;
string*v = new string[n];
for (int i = 0; i < n; i++) {
cin >> v[i];
}
for (int i = 0; i < n; i++) {
cout << v[i] << " ";
}
cout << endl;
stergereElementLung(v, n);
for (int i = 0; i < n; i++) {
cout << v[i] << " ";
}
cout << endl;
delete[]v;
}