Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

请路过的人指点一下!万分感谢.

Posted by zhengkai at 2007-09-03 13:50:49 on Problem 2254
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
struct st
{
    char Name[35];
    double Pole;//纬度 
    double jingdu;//经度 
} s[105]; 
int cmp(const void* a,const void* b)
{
    return strcmp((*(st*)a).Name,(*(st*)b).Name);
}    
int main()
{
    double Pi=3.1415926;
    int i=0;
    int j,k;
    while(scanf("%s",s[i].Name)!=EOF)
    {
    	if(strcmp(s[i].Name,"#")==0)
    		break;
	    scanf("%lf%lf",&s[i].Pole,&s[i].jingdu);
	    s[i].Pole=s[i].Pole*Pi/180;//角度化弧度 
	    s[i].jingdu=s[i].jingdu*Pi/180;
        i++; 
    }  
    qsort(s,i,sizeof(s[0]),cmp);
    char s1[35],s2[35];
    while(scanf("%s%s",s1,s2)!=EOF)
    {
        if(strcmp(s1,"#")==0&&strcmp(s2,"#")==0)
        	break;
    	int sub=strcmp(s1,s2);
    	char s3[35];
    	if(sub==0)
    		printf("0 km\n\n");
		else
		{
        	if(sub>0)
        	{
        	    strcpy(s3,s1);
        	    strcpy(s1,s2);
        	    strcpy(s2,s3);
        	} //要保证输入字符串的时候小的先找   
        	double a,b,x,y;
        	for(j=0;j<i;j++)//找小的 
        	{
        	    if(strcmp(s1,s[j].Name)==0)
        	    {
        	        a=s[j].Pole;
        	        b=s[j].jingdu;
        	        break;
        	    }    
        	} 
        	if(j<i)//找到了第一个字符串  
        	{
         		for(k=j+1;k<i;k++)//找大的 
         		{
         		    if(strcmp(s2,s[k].Name)==0)
         		    {
         		        x=s[k].Pole;
         		        y=s[k].jingdu;
         		        break;
         		    }    
         		}
           		if(k<i)//两个都找到了 
             	{
             	    double dis=6378*acos(cos(a)*cos(x)*cos(b-y)+sin(a)*sin(x));//计算公式 
    	            printf("%.lf km\n\n",dis);
              	}
               	else//只找到第一个 
                	printf("Unknown\n\n");     
       		}
         	else//两个都没找到 
          		printf("Unknown\n\n");    
        }        
    }         
	system("pause");
	return 0;
}    

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator