Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #define N 5
  4. int main(int argc, char *argv[])
  5. {
  6. FILE *fp;
  7. int x,y,z,i,j,k=0,cont=0,m[N][N],v[3],a,b;
  8. char nome[21][100],percorso[201];
  9.  
  10. for(i=0;i<N;i++)
  11. {
  12. for(j=0;j<N;j++)
  13. {
  14. m[i][j]=0;
  15. }
  16. }
  17.  
  18. if(argc!=4)
  19. {
  20. printf("Errore linea di comando\n");
  21. return -1;
  22. }
  23. fp=fopen(argv[3],"r");
  24. if(fp==NULL)
  25. {
  26. printf("errore lettura file\n");
  27. return -2;
  28. }
  29. i=0;
  30. for(z=0;z<3;z++)
  31. {
  32. fscanf(fp,"%s %d %d %s",nome[z],&x,&y,percorso);
  33. x=x-1;
  34. y=y-1;
  35. m[x][y]=1;
  36. while((percorso[k])!=EOF)
  37. {
  38. if(percorso[k]=='o' && percorso[i]=='+')
  39. y=y+1;
  40. if(percorso[k]=='o' && percorso[i]=='-')
  41. y=y-1;
  42. if(percorso[k]=='v' && percorso[i]=='+')
  43. x=x+1;
  44. if(percorso[k]=='v' && percorso[i]=='-')
  45. x=x-1;
  46.  
  47. m[x][y]=1;
  48. k++;
  49. }
  50. for(i=0;i<N;i++)
  51. {
  52. for(j=0;j<N;j++)
  53. {
  54. if(m[i][j]==1)
  55. {
  56. cont++;
  57. }
  58. }
  59. }
  60.  
  61. v[z]=cont;
  62. }
  63.  
  64. for(i=0;i<3;i++)
  65. {
  66. if(nome[i]==argv[1])
  67. {
  68. a=v[i];
  69. }
  70. else if(nome[i]==argv[2])
  71. {
  72. b=v[i];
  73. }
  74. }
  75.  
  76. if(a>b)
  77. {
  78. printf("%s %d ha fatto piu passi di %s",argv[1],v[1],argv[2]);
  79. }
  80. else
  81. {
  82. printf("%s ha fatto piu passi di %s",argv[2],argv[1]);
  83. }
  84.  
  85.  
  86. return 0;
  87.  
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement