Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdio.h>
- #include <cmath>
- using namespace std;
- typedef struct
- {
- char nume[30];
- int v;
- char ss;
- } PERS;
- int main()
- {
- PERS p[100];
- int n;
- cout << "n=";
- cin >> n;
- cout << "Date persoane(nume-varsta-stare):" << endl;
- for (int i = 0; i < n; i++)
- {
- getchar();
- gets(p[i].nume);
- cin >> p[i].v >> p[i].ss;
- }
- cout << endl;
- int x;
- do
- {
- puts("Optiune 1");
- puts("Optiune 2");
- puts("Optiune 3");
- cout << "optiune:";
- cin >> x;
- switch(x)
- {
- case 1:
- int v;
- cout << "v=";
- cin >> v;
- for (int i = 0; i < n; i++)
- if (p[i].v == v && p[i].ss == 'F')
- cout << p[i].nume << endl;
- break;
- case 2:
- {
- cout << "v=";
- cin >> v;
- int mini = abs(v - p[0].v);
- for (int i = 1; i < n; i++)
- {
- int dif = abs(v - p[i].v);
- if (mini > dif)
- mini = dif;
- }
- for (int i = 0, f = i; i < n && !f; i++)
- if (mini == abs(v - p[i].v))
- {
- f = 1;
- cout << p[i].nume << endl;
- }
- break;
- }
- case 3:
- int dr, st;
- cout << "st=";
- cin >> st;
- cout << "dr";
- cin >> dr;
- for (int i = 0, f = i; i < n && !f; i++)
- if (st <= p[i].v && p[i].v <= dr && p[i].ss == 'F')
- {
- cout << p[i].nume;
- f = 1;
- }
- break;
- case 4:
- cout << "Tasc completat!" << endl;
- break;
- default:
- cout << "Optiune inexistenta:" << endl;
- }
- }
- while (x != 4);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement