-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbiliard.cpp
71 lines (67 loc) · 1.09 KB
/
biliard.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
64
65
66
67
68
69
70
71
#include <iostream>
using namespace std;
class Stack {
private:
int size, l;
int *a;
public:
Stack (int s) {
size = s;
l=0;
a = new int[size];
}
int add(int el) {
if (l >= size) return -1;
a[l]=el;
l++;
return 0;
}
int del() {
int b;
if (l <= 0) return 0;
l--;
b = a[l];
a[l]=0;
return b;
}
};
void proverka(int * b, int n) {
int i=1;
for(i=i;b[i] > b[i-1] && i<=n;i++);
i++;
for(i=i;b[i] < b[i-1] && i<=n;i++);
if(i < n){
cout << "Ne po poryadku zabiti wari" << endl;
return;
}
cout << "wari zabiti v pravilnom poryadke" << endl;
}
int main () {
int n,i=0,*b,k,t,j;
cout << "Skolko warov" << endl;
cin >> n;
b = new int[n];
Stack a(n);
for(j=n;j>0;j--) {
cout << "Kakoy war zakatit?" << endl;
cin >> k;
a.add(k);
cout << "Pomownik vitawil?" << endl;
cin >> t;
if(t != 0) {
k = a.del();
b[i] = k;
i++;
}
}
for(k = a.del();k!=0;k = a.del()) {
b[i] = k;
i++;
}
for(i=0;i<n;i++) {
cout << b[i] << " ";
}
cout << endl;
proverka(b,n);
return 0;
}