Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- ofstream fout("sport.out");
- struct Elev {
- char nume[30];
- float h;
- } e[35];
- int n, st[35];
- void read() {
- cin >> n;
- for (int i = 1; i <= n; i++)
- cin >> e[i].nume >> e[i].h;
- }
- void sortare() {
- int sortat = 0;
- while (!sortat) {
- sortat = 1;
- for (int i = 1; i < n; i++)
- if (e[i].h > e[i + 1].h) {
- sortat = 0;
- swap(e[i], e[i + 1]);
- }
- }
- }
- void tipar() {
- for (int i = 1; i <= n; i++)
- fout << e[st[i]].nume << ' ';
- fout << endl;
- }
- int valid(int k) {
- if (e[st[k]].h < e[st[k - 1]].h)
- return 0;
- for (int i = 1; i < k; i++)
- if (st[i] == st[k])
- return 0;
- return 1;
- }
- int solutie(int k) {
- return n == k;
- }
- void bktr() {
- int k = 1;
- st[k] = 0;
- while (k) {
- if (st[k] < n) {
- st[k]++;
- if (valid(k)) {
- if (solutie(k))
- tipar();
- else {
- k++;
- st[k] = 0;
- }
- }
- }
- else
- k--;
- }
- }
- int main() {
- read();
- sortare();
- bktr();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement