Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define N 5
- int main(int argc, char *argv[])
- {
- FILE *fp;
- int x,y,z,i,j,k=0,cont=0,m[N][N],v[3],a,b;
- char nome[21][100],percorso[201];
- for(i=0;i<N;i++)
- {
- for(j=0;j<N;j++)
- {
- m[i][j]=0;
- }
- }
- if(argc!=4)
- {
- printf("Errore linea di comando\n");
- return -1;
- }
- fp=fopen(argv[3],"r");
- if(fp==NULL)
- {
- printf("errore lettura file\n");
- return -2;
- }
- i=0;
- for(z=0;z<3;z++)
- {
- fscanf(fp,"%s %d %d %s",nome[z],&x,&y,percorso);
- x=x-1;
- y=y-1;
- m[x][y]=1;
- while((percorso[k])!=EOF)
- {
- if(percorso[k]=='o' && percorso[i]=='+')
- y=y+1;
- if(percorso[k]=='o' && percorso[i]=='-')
- y=y-1;
- if(percorso[k]=='v' && percorso[i]=='+')
- x=x+1;
- if(percorso[k]=='v' && percorso[i]=='-')
- x=x-1;
- m[x][y]=1;
- k++;
- }
- for(i=0;i<N;i++)
- {
- for(j=0;j<N;j++)
- {
- if(m[i][j]==1)
- {
- cont++;
- }
- }
- }
- v[z]=cont;
- }
- for(i=0;i<3;i++)
- {
- if(nome[i]==argv[1])
- {
- a=v[i];
- }
- else if(nome[i]==argv[2])
- {
- b=v[i];
- }
- }
- if(a>b)
- {
- printf("%s %d ha fatto piu passi di %s",argv[1],v[1],argv[2]);
- }
- else
- {
- printf("%s ha fatto piu passi di %s",argv[2],argv[1]);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement