Zoj 1334 arbitrary hexadecimal conversion

Source: Internet
Author: User

# Include <iostream. h>
# Include <string. h>
# Include <math. h>
# Include <iomanip. h>
Char s [100];
Char chu [2, 1000] [100];
// Because Chu is output each time, if Chu is used again
// If there is no elimination, there is a problem, so a 1000-Bit String Array is enabled, but this is better
// The image does not solve the actual problem ......
Int main ()
{
Long from, to, A, I, J, K, temp, sum, jishu = 0;
While (CIN> S> from> )! = NULL)
{
Sum = 0;
K = strlen (s );
For (I = 0; I <K; I ++)
{
If (s [I]> '9 ')
A = s [I]-'A' + 10;
Else
A = s [I]-'0 ';
Sum + = POW (from, k-i-1) *;
}
If (! = 10)
{
J = 0;
While (sum! = 0)
{
If (sum % to> = 10)
Chu [jishu] [J] = sum % to-10 + 'a ';
Else
Chu [jishu] [J] = sum % to + '0 ';
Sum/=;
J ++;
}

For (I = 0; I <j/2; I ++)
{
Temp = chu [jishu] [I];
Chu [jishu] [I] = chu [jishu] [j-i-1];
Chu [jishu] [j-i-1] = temp;
}
If (strlen (chu [jishu]) <= 7)
Cout <setiosflags (IOs: Right) <SETW (7) <chu [jishu] <Endl;
Else
Cout <setiosflags (IOs: Right) <SETW (7) <"error" <Endl;

}

Else
{
If (sum/10000000 = 0)
Cout <setiosflags (IOs: Right) <SETW (7) <sum <Endl;
Else
Cout <setiosflags (IOs: Right) <SETW (7) <"error" <Endl;
}
Jishu ++;

 

}
Return 0;
}

 

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.