Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define N 8
- #define M 10
- int main(int argc, char *argv[])
- {
- FILE *fp;
- int m[N][M],i=0,j,max=0,found=0,cont=0,k=0,x,y,a,b,c;
- if(argc!=4)
- {
- printf("errore linea di comando\n");
- return -1;
- }
- fp=fopen(argv[1],"r");
- if(fp==NULL)
- {
- printf("errore in lettura file\n");
- return -2;
- }
- for(i=0;i<N;i++)
- {
- for(j=0;j<M;j++)
- {
- fscanf(fp,"%d",&m[i][j]);
- }
- }
- for(i=0;i<N;i++)
- {
- for(j=0;j<M;j++)
- {
- printf("%d\t",m[i][j]);
- }
- printf("\n\n\n");
- }
- for(i=0;i<N;i++)
- {
- k=i;
- cont=0;
- for(j=0;j<(N-i);j++)
- {
- if(m[k][j]==0)
- {
- found=0;
- cont=0;
- }
- else if(m[k][j]==1)
- {
- found=1;
- }
- if(found==1)
- {
- cont++;
- if(max<cont)
- {
- max=cont;
- c=1;
- }
- }
- k++;
- }
- }
- for(j=(M-N);j<M;j++)
- {
- k=j;
- cont=0;
- for(i=0;i<(M-j);i++)
- {
- if(m[i][k]==0)
- {
- found=0;
- cont=0;
- }
- else if(m[i][k]==1)
- {
- found=1;
- }
- if(found==1)
- {
- cont++;
- if(max<cont)
- {
- max=cont;
- c=2;
- }
- }
- k++;
- }
- }
- x=0;
- j=0;
- while(y!=M)
- {
- y=j;
- while(x!=N)
- {
- if(m[x][y]==0)
- {
- found=0;
- cont=0;
- }
- else if(m[x][y]==1)
- {
- found=1;
- }
- if(found==1)
- {
- cont++;
- if(max<cont)
- {
- max=cont;
- c=3;
- }
- }
- x++;
- y++;
- }
- cont=0;
- x=0;
- j++;
- }
- fclose(fp);
- printf("la piu lunga e' %d zona=%d %d %d",max,c,a,b);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement