#include
using namespace std;
void work(short *, const size_t);
void show(short *, const size_t);
int main() {
size_t size;
short a[] = { 1, 0, 3, 0, 7 };
size = sizeof(a) / sizeof(short);
show(a, size);
work(a, size);
short b[] = { 1, 2, 3, 4, 5, 6 };
size = sizeof(b) / sizeof(short);
show(b, size);
work(b, size);
short c[] = { 1, 2, 3, 0, 5, 7, 8 };
size = sizeof(c) / sizeof(short);
show(c, size);
work(c, size);
cin.get();
return 0;
}
void show(short * _v, const size_t _sz) {
for (unsigned n = 0; n < _sz; n++) cout << ' ' << _v[n];
cout << endl;
}
void work(short * _v, const size_t _sz) {
bool beg = false, end = false;
unsigned bg = -1, ed = -1;
for (unsigned n = 0, m = _sz - 1; n <= m; n++, m--) {
if (!beg && !_v[n]) {
beg = true;
bg = n;
++bg;
}
if (!end && !_v[m]) {
end = true;
ed = m;
++ed;
}
if (beg && end) break;
}
if (beg && end) cout << " first: " << bg << endl << " second: " << ed;
else if (beg) cout << " first: " << bg << endl << " second: " << bg;
else if (end) cout << " first: " << ed << endl << " second: " << ed;
else cout << " Not zero!";
cout << endl << endl;
}