Cod sursa(job #115048)
Utilizator | Data | 16 decembrie 2007 10:27:13 | |
---|---|---|---|
Problema | Operatii | Scor | 0 |
Compilator | cpp | Status | done |
Runda | preONI 2008, Runda 2, Clasa a 9-a | Marime | 0.28 kb |
#include <fstream.h>
ifstream f("operatii.in");
ofstream g("operatii.out");
void main()
{int n,i,x=0,a=0,b=0,v[1000000];f>>n;
for (i=1;i<=n;i++) f>>v[i];
i=1;
while (i<=n)
{if (v[i]==0) {a=0;b=0;}
else {b=a;a=v[i];if (b==0) x=x+a;else if (a>b) x=x+a-b;}
i++;}
g<<x;}