2009年7月30日 星期四

ACM Q10110


#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;
}

1 則留言:

  1. signed 和 unsigned int 有些許的不同:

    1. unsigned int 的range 是signed int 的兩倍

    2. 兩者比較大小時, signed int 會被轉成unsigned int 來比較

    3. 在做資料轉換時,signed int 前面會補1 unsigned 會補0

    回覆刪除