POJ 1220 number BASE CONVERSION High precision binary conversion

Source: Internet
Author: User
Tags ibase

POJ 50 photo shoot photo Souvenir

Number BASE CONVERSION
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 4620 Accepted: 2115

Description

Write a program to convert numbers in one base to numbers in a second base. There is different digits:
{0-9,a-z,a-z}
Hint:if a sequence of base conversions using the output of one conversion as the input to the next, when you get Back to the original base, you should get the original number.

Input

The first line of input contains a single positive integer. This is the number of lines that follow. Each of the following lines would have a (decimal) input base followed by a (decimal) output base followed by a number expr Essed in the input base. Both the input base and the output base is in the range from 2 to 62. That was (in decimal) A = ten, B = One, ..., z = +, A = $, B = Notoginseng, ..., z = (0-9 have their usual meanings).

Output

The output of the program should consist of three lines of output for each base conversion performed. The first line should is the input base in decimal followed by a space then the input number (as given expressed in the Put base). The second output line should is the output base followed by a space then the input number (as expressed in the output bas e). The third output line is blank.

Sample Input

862 2 abcdefghiz10 123456789012345678901234567890123456789016 3a0c92075c0dbf3b8acbc5f96ce3f0ad235 23 333ymhoue8jplt7ox6k9fycq8a23 946b9aa02mi37e3d3mmj4g7bl2f0549 1vbdksimjl3jjrgadlufcawj61 5 DL9MDSWQWHJDNTOKCSWE1S5 10 42104444441001414401221302402201233340311104212022133030

Sample Output

ABCDEFGHIZ2 1101110000010001011111001001011001111100100110001101001000110 123456789012345678901234567890123456789016 3a0c92075c0dbf3b8acbc5f96ce3f0ad216 3a0c92075c0dbf3b8acbc5f96ce3f0ad235 333ymhoue8jplt7ox6k9fycq8a35 333ymhoue8jplt7ox6k9fycq8a23 946b9aa02mi37e3d3mmj4g7bl2f0523 946b9aa02mi37e3d3mmj4g7bl2f0549 1vbdksimjl3jjrgadlufcawj49 1vbdksimjl3jjrgadlufcawj61 dl9mdswqwhjdntokcswe1s61 DL9MDSWQWHJDNTOKCSWE1S5 421044444410014144012213024022012333403111042120221330305 4210444444100141440122130240220123334031110421202213303010 1234567890123456789012345678901234567890

Source

Greater New York 2002 arbitrary Conversion

AC

#include <iostream> #include <cstring> #include <cstdio> #define MAXN 999int Aa[maxn],bb[maxn];char a[ Maxn],b[maxn];using namespace Std;int main () {    int loop,ibase,obase,i,count,len,j;     cin>>loop;    while (loop--) {        scanf ("%d%d%s" , &ibase,&obase,a);        Len=strlen (a);         for (i=len-1,j=0;i>=0;--i)         aa[j++]=a[i]-(a[i]< = ' 9 '?48:a[i]< ' a '? 55:61);        count=0;         while (len>0) {            j=len-1;             while (j) {                 aa[j-1]+=aa[j]%obase*ibase;         &nbSp      aa[j]/=obase;                 j--;            }            bb[count++]=aa[0]%obase;            aa[0]/=obase;            while (0<len&&!aa[len-1]) len--;        }       ///printf ("count=%d\n", Count);        for (b[count]= ', i=count-1,j=0;i>=0;i--, j + +)         b[ j]=bb[i]+ (bb[i]<10?48:bb[i]<36?55:61);        printf ("%d%s\n%d%s\n\n", IBASE,A,OBASE,B);   }    return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

POJ 1220 number BASE CONVERSION High precision binary conversion

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.