Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

wa到吐血,求救

Posted by lingshanxiaoyao at 2008-11-15 14:25:32 on Problem 1546
#include <iostream>
using namespace std;

char input[8],b1,b2,ans[8];

int change1(char ch)
{
    if(ch>='A') return ch-'A'+10;
    return ch-'0';
}

char change2(int x)
{
    if(x<10) return (char)(x)+'0';
    return (char)(x-10)+'A';
}


int main()
{    
    while(scanf("%s %d %d",input,&b1,&b2)!=EOF)
    {
        int len=strlen(input),number=0,power=1;
        for(int i=len-1;i>=0;i--)
        {
            number +=change1(input[i])*power;
            power*=b1;
        }
        if(number==0){
            printf("      0\n");
            continue;
        }
        
        int k=0;
        while(number)
        {
            ans[k++]=change2(number%b2);
            number/=b2;
        }
        if(k>7){
            printf("  ERROR\n");
            continue;
        }
        for(int i=7;i>k;i--)
            putchar(' ');
        for(k--;k>=0;k--)
            putchar(ans[k]);
        putchar('\n');
        
    }
    
    return 0;
    
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator