Source Code:
#include<stdio.h>
#include<math.h>
#include<string.h>
int main()
{
int trip,i,x,y,E=0,W=0,N=0,S=0;
scanf("%d",&trip);
float dis[trip],speed[trip],total=0;
char dir[trip];
for(i=0;i<trip;i++)
{
scanf("%f %f %c",&dis[i],&speed[i],&dir[i]);
total=total+((dis[i]/speed[i])*60);
}
printf("%.f\n",ceil(total));
for(i=0;i<trip;i++)
{
if(dir[i]=='N')
N=dis[i];
if(dir[i]=='S')
S=dis[i];
if(dir[i]=='E')
E=dis[i];
if(dir[i]=='W')
W=dis[i];
}
x=E-W;
y=N-S;
if(x>0&&y>0)
printf("NE");
if(x<0&&y<0)
printf("SW");
if(x<0&&y>0)
printf("NW");
if(x>0&&y<0)
printf("SE");
if(x==0&&y>0)
printf("N");
if(x>0&&y==0)
printf("E");
if(x<0&&y==0)
printf("W");
if(x<0&&y<0)
printf("S");
return 0;
}
#include<stdio.h>
#include<math.h>
#include<string.h>
int main()
{
int trip,i,x,y,E=0,W=0,N=0,S=0;
scanf("%d",&trip);
float dis[trip],speed[trip],total=0;
char dir[trip];
for(i=0;i<trip;i++)
{
scanf("%f %f %c",&dis[i],&speed[i],&dir[i]);
total=total+((dis[i]/speed[i])*60);
}
printf("%.f\n",ceil(total));
for(i=0;i<trip;i++)
{
if(dir[i]=='N')
N=dis[i];
if(dir[i]=='S')
S=dis[i];
if(dir[i]=='E')
E=dis[i];
if(dir[i]=='W')
W=dis[i];
}
x=E-W;
y=N-S;
if(x>0&&y>0)
printf("NE");
if(x<0&&y<0)
printf("SW");
if(x<0&&y>0)
printf("NW");
if(x>0&&y<0)
printf("SE");
if(x==0&&y>0)
printf("N");
if(x>0&&y==0)
printf("E");
if(x<0&&y==0)
printf("W");
if(x<0&&y<0)
printf("S");
return 0;
}
Input:
3
10 20 N
20 50 E
5 100 S
Output:
57
NE
0 comments:
Post a Comment