PersonalCorpus 版 (精华区)

41334 2002-10-13 20:23:42 Accepted
1334 C++ 00:00.00 380K Big Guava


static char p[17]="0123456789ABCDEF";

int main()
{
#ifndef ONLINE_JUDGE
    freopen("c:\\0acm\\zju\\i1334","r",stdin);
    freopen("c:\\0acm\\zju\\o1334","w",stdout);
#endif

    char s[100],ch;
    int i,j,k,a,b,c;

    while (gets(s)!=NULL) {
        i=strlen(s)-1;
        while (s[i]==' ') i--;
        while (s[i]!=' ') i--;
        sscanf(s+i+1,"%d",&c);
        while (s[i]==' ') i--;
        while (s[i]!=' ') i--;
        sscanf(s+i+1,"%d",&b);
        i=0; while (s[i]==' ') i++;
        a=0; k=0;
        while (s[i]!=' ') {
            a*=b;
            if ((s[i]>='0')&&(s[i]<='9')) j=s[i]-48; else j=s[i]-55;
            if (j>=b) {
                k=-1;
                printf("  ERROR\n");
                break;
            }
            a+=j; i++;
        }
        if (k==-1) continue;
        memset(s,0,sizeof(s));
        i=0;
        while (a!=0) {
            s[i++]=p[a%c];
            a/=c;
        }
        if (strlen(s)>7) printf("  ERROR\n");
        else {
            for (i=0;i<7-strlen(s);i++) printf(" ");
            for (i=strlen(s)-1;i>=0;i--) printf("%c",s[i]);
            printf("\n");
        }
    }
}
[百宝箱] [返回首页] [上级目录] [根目录] [返回顶部] [刷新] [返回]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:4.693毫秒