View Code of Problem 62

#include<stdio.h>
#include<string.h>
int main(){
	int m,n,i,j,sum,t,len;
	char str[120];
	while(scanf("%d%d",&m,&n) &&(m||n))
	{
		int a[120][120]={0};
		for(i=0;i<m;i++)
		{
			scanf("%s",&str);
			len=strlen(str);
			for(j=0;j<len;j++)
			{
				if(str[j]=='0')
					a[i][j]=0;
				else
					a[i][j]=1;
			}
		}
		for(t=sum=i=0;i<m;i++)
		{
			t=sum;
			for(j=0;j<n;j++)
			{
				if(a[i][j]==1)
				{
					sum++;
					j=j+2;
				}	
			}
			if(sum>t)
				i=i+2;
		}
		printf("%d\n",sum);
	}

	return 0;
}

Double click to view unformatted code.


Back to problem 62