#include "stdafx.h" #include <iostream> using namespace std; int main() { int a, b, k=0, c=1; bool t = false; if (cin >> a && a != 0) if (cin >> b && b != 0) if (b > a) t = true; while (c != 0&&a!=0&&b!=0) { cin >> c; if (c == 0) break; if (t) if (c < b) k++; t = false; a = b; b = c; if (b > a) t = true; } cout << endl << k << endl; system("pause"); return 0; }
Answers & Comments
Verified answer
Visual Studio 2017 C++#include "stdafx.h"
#include <iostream>
using namespace std;
int main() {
int a, b, k=0, c=1; bool t = false;
if (cin >> a && a != 0)
if (cin >> b && b != 0)
if (b > a) t = true;
while (c != 0&&a!=0&&b!=0) {
cin >> c; if (c == 0) break;
if (t) if (c < b) k++;
t = false;
a = b; b = c;
if (b > a) t = true;
}
cout << endl << k << endl;
system("pause");
return 0;
}
using namespace std;
int main()
{
int num, tmp1, tmp2, count = 0;
if (cin >> num && num != 0)
{
tmp1 = num;
if (cin >> num && num != 0)
{
tmp2 = num;
while (cin >> num && num != 0)
{
if (tmp2 > tmp1 && tmp2 > num)
count++;
tmp1 = tmp2;
tmp2 = num;
}
}
}
cout << endl << count << endl;
system("pause");
return 0;
}