Pagini recente » Cod sursa (job #798546) | Cod sursa (job #1305381) | Cod sursa (job #837594) | Cod sursa (job #1409853) | Cod sursa (job #305330)
Cod sursa(job #305330)
#include<fstream.h>
int main()
{
long long n,i,ok1,nr,ok,a[100000];
ifstream f("operatii.in");
ofstream g("sumdiv.out");
f>>n;
for (i=1;i<=n;i++)
f>>a[i];
ok=0;
while (ok=0)
{
ok1=0;
for (i=1;i<=n;i++)
if (a[i]>0){
a[i]--;
ok1=1;
if (a[i+1]==0)break;
}
else if ((ok1==1)&&(a[i]==0)) break;
nr++;
ok=1;
for (i=1;i<=n;i++)
if (a[i]>0) {
ok--;
break;
}
}
g<<nr;
f.close();
g.close();
return 0;
}