Hangzhou Electric HDU ACM 1335 basically Speaking

Source: Internet
Author: User

Basically Speaking Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 2532 Accepted Submission (s): 959

Problem DescriptionThe really Neato Calculator Company, Inc. have recently hired your team to help design their Super Neato Model I Calculator. As a computer scientist you suggested to the company so it would be neato if this new calculator could convert among num BER bases. The company thought this is a stupendous idea and have asked your team to come up with the prototype program for doing BAS E conversion. The project manager of the Super Neato Model I Calculator has informed you and the calculator would have the following NEA To features:
It would have a 7-digit display.

Its buttons would include the capital letters A through F in addition to the digits 0 through 9.

It would support bases 2 through 16.

Inputthe input for your prototype program would consist of one base conversion per line. There'll is three numbers per line. The first number would be being the number in the base converting from. The second number is the base of converting from. The third number is the base of you and converting to. There'll be is one or more blanks surrounding (on either side of) the numbers. There is several lines of input and your program should continue to read until the end of file is reached.

Outputthe output is the converted number as it would appear on the display of the calculator. The number should is right justified in the 7-digit display. If the large to appear on the display and then print "ERROR" (without the quotes) right justified in the DISPLA Y.

Sample Input
1111000  2 101111000  2 162102101  3 102102101  3  12312  4  2     1 a  21234567 10 16   ABCD 16 15

Sample Output
   1765    7CA  ERROR  11001 12d687   D071

Sourcemid-central USA 1995 What's wrong with the value conversion today? Another, note that the number to be converted may have a--z, so string ... : The idea is to first convert to decimal and then convert to R binary.
#include <iostream> #include <string> #include <math.h>using namespace Std;int A (string & str,int m ) {int X=0,b,t,sum=0;int len=str.size () -1;while ((len+1) >0) {if (str[len]>= ' A ' &&str[len]<= ' Z ') b=str [len]-' A ' +10;elseb=str[len]-' 0 '; Sum+=b*pow (m,x); x++;len--;} return sum;} void ls (int a,int c) {char x[1000];int t=0;while (a) {int m=a%c;    if (m>9)      x[t++]=m-10+ ' A '; else  x[t++]=m+ ' 0 ';     A/=c;} if (t>7) cout<< "  ERROR" <<endl;else{for (int i=0;i<7-t;i++) cout<< ""; for (int j=t-1;j>= 0;j--) Cout<<x[j];cout<<endl;}} int main () {int b,c;string str;while (cin>>str>>b>>c)    ls (A (str,b), c); return 0;}

Hangzhou Electric HDU ACM 1335 basically Speaking

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.