Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
wa到吐血,求救#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator