#include <iostream> #include <math.h> using namespace std; int main(void){ unsigned int N; while(true){ cin>>N; if(N==0) break; if((int)(sqrt(N))*(int)(sqrt(N))==N) cout<<"yes"<<endl; else cout<<"no"<<endl; } return 0; }
下面是錯誤的code:
#include <iostream> #include <math.h> using namespace std; int main(void){ long long int N; while(true){ cin>>N; if(N==0) break; if((int)(sqrt(N))*(int)(sqrt(N))==N) cout<<"yes"<<endl; else cout<<"no"<<endl; } return 0; }
signed 和 unsigned int 有些許的不同:
回覆刪除1. unsigned int 的range 是signed int 的兩倍
2. 兩者比較大小時, signed int 會被轉成unsigned int 來比較
3. 在做資料轉換時,signed int 前面會補1 unsigned 會補0