Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <cstring>
- using namespace std;
- ifstream fin("cuvinte.in");
- int n;
- struct nod
- {
- char cuvant[25];
- nod *leg;
- } *prim;
- void ad_dupa(nod *&prim, nod *q, char x[25])
- {
- nod *r = new nod;
- strcpy(r -> cuvant, x);
- r -> leg = q -> leg;
- q -> leg = r;
- }
- void ad_sf(nod *&prim, char cuv[25])
- {
- nod *p = new nod;
- nod *q;
- p -> leg = NULL;
- strcpy(p -> cuvant, cuv);
- if (prim == NULL)
- {
- prim = p;
- }
- else
- {
- q = prim;
- while (q -> leg != NULL)
- {
- q = q -> leg;
- }
- q -> leg = p;
- }
- }
- void creare_lista(nod *&prim)
- {
- nod *p;
- char c[25];
- int ok;
- fin >> n;
- for (int i = 1; i <= n; ++i)
- {
- fin >> c;
- ok = 1;
- p = prim;
- while (p)
- {
- if (strcmp(p -> cuvant, c) == 0)
- {
- ok = 0;
- }
- p = p -> leg;
- }
- if (ok == 1)
- ad_sf(prim, c);
- }
- }
- void afisare(nod *prim)
- {
- nod *p;
- for (p = prim; p != NULL; p = p -> leg)
- {
- cout << p -> cuvant << ' ';
- }
- cout << endl;
- }
- void ordonare(nod *&prim)
- {
- nod *q, *p;
- for (p = prim; p -> leg != NULL; p = p -> leg)
- {
- for (q = p -> leg; q; q = q -> leg)
- {
- if (strlen(q -> cuvant) < strlen(p -> cuvant))
- {
- swap(q -> cuvant, p -> cuvant);
- }
- }
- }
- }
- void rezolvare(nod *prim)
- {
- int maxim = 0;
- nod *p = prim;
- while (p)
- {
- if (strlen(p -> cuvant) > maxim)
- {
- maxim = strlen(p -> cuvant);
- }
- p = p -> leg;
- }
- p = prim;
- while (p)
- {
- if (strlen(p -> cuvant) == maxim)
- {
- cout << p -> cuvant << ' ';
- }
- p = p -> leg;
- }
- }
- void rzv(nod *&prim)
- {
- char C[25] = "mylist";
- nod *p = prim;
- while (p)
- {
- if (strlen(p -> cuvant) % 2 == 0)
- {
- ad_dupa(prim, p, C);
- p = p -> leg;
- }
- p = p -> leg;
- }
- }
- int main()
- {
- creare_lista(prim);
- cout << "Cerinta a) ";
- afisare(prim);
- cout << "Cerinta b) ";
- ordonare(prim);
- afisare(prim);
- cout << "Cerinta c) ";
- rezolvare(prim);
- cout << endl;
- cout << "Cerinta d) ";
- rzv(prim);
- afisare(prim);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement