diff options
author | InigoGutierrez <inigogf.95@gmail.com> | 2019-05-28 18:59:15 +0200 |
---|---|---|
committer | InigoGutierrez <inigogf.95@gmail.com> | 2019-05-28 18:59:15 +0200 |
commit | a0164a1487fd419b88718cad4b20fab65e93e865 (patch) | |
tree | 406ac27d733f467df2dd284282d37eb6c4180152 /c | |
parent | d938f6fc299752dd454cc90d928173bed70882f5 (diff) | |
download | AceptaElReto-a0164a1487fd419b88718cad4b20fab65e93e865.tar.gz AceptaElReto-a0164a1487fd419b88718cad4b20fab65e93e865.zip |
Resuelto 376 en c++: Siete picos.
Diffstat (limited to 'c')
-rw-r--r-- | c/376_sietePicos.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/c/376_sietePicos.cpp b/c/376_sietePicos.cpp new file mode 100644 index 0000000..1fbeba9 --- /dev/null +++ b/c/376_sietePicos.cpp @@ -0,0 +1,29 @@ +#include <iostream> + +using namespace std; + +int main() { + int size; + int prev, next; + int picos; + cin>>size; // Primera lectura del tamaƱo fuera del bucle para primera comprobaciĆ³n + while (size != 0) { + int heights[size]; + // Lee todas las alturas + for (int i = 0; i < size; i++) { + cin>>heights[i]; + } + picos = 0; + // Comprueba todas las alturas + for (int i = 0; i < size; i++) { + prev = i-1; + if (prev < 0) + prev = size-1; + next = (i+1)%size; + if (heights[i] > heights[prev] && heights[i] > heights[next]) + picos++; + } + cout<<picos<<endl; + cin>>size; + } +} |