Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #define N 8
  4. #define M 10
  5. int main(int argc, char *argv[])
  6. {
  7. FILE *fp;
  8. int m[N][M],i=0,j,max=0,found=0,cont=0,k=0,x,y,a,b,c;
  9. if(argc!=4)
  10. {
  11. printf("errore linea di comando\n");
  12. return -1;
  13. }
  14. fp=fopen(argv[1],"r");
  15. if(fp==NULL)
  16. {
  17. printf("errore in lettura file\n");
  18. return -2;
  19. }
  20.  
  21. for(i=0;i<N;i++)
  22. {
  23. for(j=0;j<M;j++)
  24. {
  25. fscanf(fp,"%d",&m[i][j]);
  26. }
  27. }
  28. for(i=0;i<N;i++)
  29. {
  30. for(j=0;j<M;j++)
  31. {
  32. printf("%d\t",m[i][j]);
  33. }
  34. printf("\n\n\n");
  35. }
  36.  
  37. for(i=0;i<N;i++)
  38. {
  39. k=i;
  40. cont=0;
  41. for(j=0;j<(N-i);j++)
  42. {
  43. if(m[k][j]==0)
  44. {
  45. found=0;
  46. cont=0;
  47. }
  48. else if(m[k][j]==1)
  49. {
  50. found=1;
  51. }
  52. if(found==1)
  53. {
  54. cont++;
  55. if(max<cont)
  56. {
  57. max=cont;
  58. c=1;
  59. }
  60. }
  61. k++;
  62. }
  63. }
  64.  
  65. for(j=(M-N);j<M;j++)
  66. {
  67. k=j;
  68. cont=0;
  69. for(i=0;i<(M-j);i++)
  70. {
  71. if(m[i][k]==0)
  72. {
  73. found=0;
  74. cont=0;
  75. }
  76. else if(m[i][k]==1)
  77. {
  78. found=1;
  79. }
  80. if(found==1)
  81. {
  82. cont++;
  83. if(max<cont)
  84. {
  85. max=cont;
  86. c=2;
  87. }
  88. }
  89. k++;
  90. }
  91.  
  92. }
  93. x=0;
  94. j=0;
  95.  
  96. while(y!=M)
  97. {
  98. y=j;
  99. while(x!=N)
  100. {
  101. if(m[x][y]==0)
  102. {
  103. found=0;
  104. cont=0;
  105. }
  106. else if(m[x][y]==1)
  107. {
  108. found=1;
  109. }
  110. if(found==1)
  111. {
  112. cont++;
  113. if(max<cont)
  114. {
  115. max=cont;
  116. c=3;
  117. }
  118. }
  119. x++;
  120. y++;
  121. }
  122. cont=0;
  123. x=0;
  124. j++;
  125. }
  126.  
  127. fclose(fp);
  128.  
  129. printf("la piu lunga e' %d zona=%d %d %d",max,c,a,b);
  130.  
  131.  
  132. return 0;
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement