#561: 請問這題CE


luckysky (luckysky)

學校 : 國立中央大學
編號 : 2338
來源 : [140.115.217.26]
最後登入時間 :
2008-12-01 22:51:05
c092. 00587 - There's treasure everywhere! -- UVa587 | From: [61.229.83.173] | 發表日期 : 2008-09-09 22:35

編譯錯誤, 請檢查語法是否符合系統所支援的編譯器的要求。
錯誤訊息:
/tmp/code_45323.cpp: In function `int main(int, char**)':
/tmp/code_45323.cpp:41: error: call of overloaded `sqrt(int)' is ambiguous
/usr/include/bits/mathcalls.h:157: error: candidates are: double sqrt(double)
/usr/include/c++/3.3/cmath:550: error:                 long double
   std::sqrt(long double)
/usr/include/c++/3.3/cmath:546: error:                 float std::sqrt(float)
/tmp/code_45323.cpp:44: error: call of overloaded `sqrt(int)' is ambiguous
/usr/include/bits/mathcalls.h:157: error: candidates are: double sqrt(double)
/usr/include/c++/3.3/cmath:550: error:                 long double
   std::sqrt(long double)
/usr/include/c++/3.3/cmath:546: error:                 float std::sqrt(float)
/tmp/code_45323.cpp:47: error: call of overloaded `sqrt(int)' is ambiguous
/usr/include/bits/mathcalls.h:157: error: candidates are: double sqrt(double)
/usr/include/c++/3.3/cmath:550: error:                 long double
   std::sqrt(long double)
/usr/include/c++/3.3/cmath:546: error:                 float std::sqrt(float)
/tmp/code_45323.cpp:50: error: call of overloaded `sqrt(int)' is ambiguous
/usr/include/bits/mathcalls.h:157: error: candidates are: double sqrt(double)
/usr/include/c++/3.3/cmath:550: error:                 long double
   std::sqrt(long double)
/usr/include/c++/3.3/cmath:546: error:                 float std::sqrt(float) 
#562: Re:請問這題CE


luckysky (luckysky)

學校 : 國立中央大學
編號 : 2338
來源 : [140.115.217.26]
最後登入時間 :
2008-12-01 22:51:05
c092. 00587 - There's treasure everywhere! -- UVa587 | From: [61.229.83.173] | 發表日期 : 2008-09-09 22:36

  1. #include <cstdlib>   
  2. #include <iostream>   
  3. #include <cmath>   
  4.   
  5. using namespace std;   
  6.   
  7. int f(char c){   
  8.     if(c=='N' || c=='S' || c=='W' || c=='E'){   
  9.         return 1;   
  10.     }   
  11.     else{   
  12.         return 0;   
  13.     }   
  14. }   
  15.   
  16. int main(int argc, char *argv[])   
  17. {   
  18.     char a[300];   
  19.     double N=0,S=0,W=0,E=0,ans;   
  20.     int temp=0,T=0;   
  21.     bool kk;   
  22.     while(cin>>a){   
  23.         if(a[0]=='E' && a[1]=='N' && a[2]=='D' && a[3]=='\0'){   
  24.             break;   
  25.         }   
  26.         T++;   
  27.         kk=false;   
  28.         N=0;   
  29.         S=0;   
  30.         W=0;   
  31.         E=0;   
  32.         for(int i=0;i<strlen(a)-1;i++){   
  33.             if(a[i]>='0' && a[i]<='9'){   
  34.                 temp*=10;   
  35.                 temp+=a[i]-'0';   
  36.                 kk=true;   
  37.             }   
  38.             else if(kk==true){   
  39.                 if(f(a[i+1])==1){   
  40.                     if(a[i+1]=='N' || a[i]=='N' ){   
  41.                         N+=temp/sqrt(2);   
  42.                     }   
  43.                     if(a[i+1]=='S' || a[i]=='S' ){   
  44.                         S+=temp/sqrt(2);   
  45.                     }   
  46.                     if(a[i+1]=='W' || a[i]=='W' ){   
  47.                         W+=temp/sqrt(2);   
  48.                     }   
  49.                     if(a[i+1]=='E' || a[i]=='E' ){   
  50.                         E+=temp/sqrt(2);   
  51.                     }   
  52.                 }   
  53.                 else{   
  54.                     if(a[i]=='N'){   
  55.                         N+=temp;   
  56.                     }   
  57.                     if(a[i]=='S'){   
  58.                         S+=temp;   
  59.                     }   
  60.                     if(a[i]=='W'){   
  61.                         W+=temp;   
  62.                     }   
  63.                     if(a[i]=='E'){   
  64.                         E+=temp;   
  65.                     }   
  66.                 }   
  67.                 kk=false;   
  68.                 temp=0;   
  69.             }   
  70.         }   
  71.         E-=W;   
  72.         N-=S;   
  73.         ans=E*E+N*N;   
  74.         ans=sqrt(ans);   
  75.         cout.precision(3);   
  76.         if(T!=1){   
  77.             cout<<endl;   
  78.         }   
  79.         cout<<"Map #"<<T<<endl;   
  80.         cout<<"The treasure is located at ("<<fixed<<E<<","<<fixed<<N<<")."<<endl;   
  81.         cout<<"The distance to the treasure is "<<fixed<<ans<<"."<<endl;   
  82.     }   
  83.     system("PAUSE");   
  84.     return EXIT_SUCCESS;   
  85. }  
    感謝幫看
 
#565: Re:請問這題CE


POOHccc ()

學校 : 國立臺中技術學院
編號 : 1139
來源 : [220.135.97.253]
最後登入時間 :
2012-02-04 21:23:42
c092. 00587 - There's treasure everywhere! -- UVa587 | From: [220.135.97.253] | 發表日期 : 2008-09-10 08:30

sqrt(2)請改成sqrt(2.0)或是sqrt((double)2)

另外system("pause")也請拿掉

 
#577: Re:請問這題CE


luckysky (luckysky)

學校 : 國立中央大學
編號 : 2338
來源 : [140.115.217.26]
最後登入時間 :
2008-12-01 22:51:05
c092. 00587 - There's treasure everywhere! -- UVa587 | From: [140.115.217.26] | 發表日期 : 2008-09-14 08:53

sqrt(2)請改成sqrt(2.0)或是sqrt((double)2)

另外system("pause")也請拿掉 



3QQ 
ZeroJudge Forum