Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
相当诡异#include<stdio.h> #include<string.h> #include<math.h> #include<stdlib.h> #define PI 3.141592653589793 #define R 6378 typedef struct{ char name[30]; double x, y, z; }CITY; CITY city[1000]; int ncity = 0; int read(){ double lon, lat; scanf("%s", city[ncity].name); if(strcmp(city[ncity].name, "#") == 0) return 0; scanf("%lf %lf", &lat, &lon); lon *= PI / 180.0; lat *= PI / 180.0; city[ncity].x = sin(lon) * cos(lat); city[ncity].y = cos(lon) * cos(lat); city[ncity].z = sin(lat); ncity++; return 1; } double distance(int i, int j){ double al = acos(city[i].x * city[j].x + city[i].y * city[j].y + city[i].z * city[j].z); return al * R; } int solve(){ int i, j; char src[30], dst[30]; scanf("%s %s", src, dst); if(strcmp(src, "#") == 0) return 0; printf("%s - %s\n", src, dst); for (i = 0 ; i < ncity && strcmp(city[i].name, src) ; i++); for (j = 0 ; j < ncity && strcmp(city[j].name, dst) ; j++); if (i == ncity || j == ncity) printf("Unknown\n\n"); else printf("%.0f km\n\n", distance(i, j)); return 1; } int main(){ while (read()); while (solve()); //system("PAUSE"); return 0; } 输出时,用%.0lf就WA Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator