杭电ACM 第2097题

#include<iostream>
#include<math.h>
#include<string>
#include<stdlib.h>
using namespace std;

string jzzh(int s,int z){
    int a,b,c,d;
    string str="";
    string str1="";
    a=s;
    b=z;
    c=a/b;
    d=a%b;
    if(d<10){

    str+=d+'0';
    }
    else{
        str+=d+'A'-10;
    }
    while(c){
        a=c;
        c=a/b;
        d=a%b;
        if(d<10){
            str+=d+'0';
        }
        else
            str+=d+'A'-10;
    }
    for(int i=str.length()-1;i>=0;--i){
        str1+=str[i];
    }
    return str1;
}

void main(){
    int n;
    while(cin>>n){
        if(n==0)
            break;
        int s10,s12,s16;
        s10=s12=s16=0;
        int s=n;
        while(s){
            s10+=s%10;
            s/=10;
        }
        
        string str=jzzh(n,16);
        
        for(int i=0;i<str.length();++i){
            if(str[i]>='0'&&str[i]<='9'){
                s16+=str[i]-'0';
            }
            else{
                s16+=str[i]-'A'+10;
            }
        }
        if(s10==s16){
            str=jzzh(n,12);
            for(int j=0;j<str.length();++j){
                if(str[j]>='0'&&str[j]<='9'){
                s12+=str[j]-'0';
            }
            else{
                s12+=str[j]-'A'+10;
            }
            }
            if(s12==s10){
                cout<<n<<" "<<"is a Sky Number."<<endl;
            }
            else
                cout<<n<<" is not a Sky Number."<<endl;
            
        }
        else{
            cout<<n<<" "<<"is not a Sky Number."<<endl;
        }
        
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值