#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
#define sc(n) scanf("%d", &n)
#define sf scanf
#define pf printf
#define MX 10005
typedef long long ll;
int a[MX];
int main()
{
int i, n, cnt, Zcnt;
while(sc(n)==1)
{
cnt = 0;
Zcnt=0;
for(i=0; i<n; i++)
{
sc(a[i]);
if(a[i]==1)
cnt++;
else if(a[i]==0 && a[i-1]!=0)
cnt++;
else if(a[i]==0)
Zcnt++;
}
if(a[n-1]==0 && Zcnt!=n)
cnt--;
pf("%d\n", cnt);
}
return 0;
}
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
#define sc(n) scanf("%d", &n)
#define sf scanf
#define pf printf
#define MX 10005
typedef long long ll;
int a[MX];
int main()
{
int i, n, cnt, Zcnt;
while(sc(n)==1)
{
cnt = 0;
Zcnt=0;
for(i=0; i<n; i++)
{
sc(a[i]);
if(a[i]==1)
cnt++;
else if(a[i]==0 && a[i-1]!=0)
cnt++;
else if(a[i]==0)
Zcnt++;
}
if(a[n-1]==0 && Zcnt!=n)
cnt--;
pf("%d\n", cnt);
}
return 0;
}
No comments:
Post a Comment