Last active
November 4, 2015 03:42
-
-
Save frzleaf/2be731579f61ff7a8dcf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Bai 4.21 | |
* Le Quang Thanh - 11020287 | |
*/ | |
#include <iostream> | |
#include <stdlib.h> | |
#include <string> | |
template<typename T> | |
int longest_highland(const T *a, int len) { | |
int res = 0; | |
int cur = 0; | |
for (int i = 1; i < len; ++i) { | |
if (a[i] > a[i - 1]) { | |
cur = 1; | |
for (int j = i; j < len - 1; ++j) { | |
if (a[j] == a[j + 1]) { | |
++cur; | |
} else if (a[j] > a[j + 1]) { | |
res = (cur > res) ? cur : res; | |
} else { | |
break; | |
} | |
} | |
} | |
} | |
return res; | |
} | |
int main() { | |
int b[] = {1,2,2,2,2,1,3,4,5,6}; | |
int *a = b; | |
std::cout << longest_highland(a, 6); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment