Hdu 1335 basically Speaking (analog conversion) __HDU

Source: Internet
Author: User
basically Speaking Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 2909 accepted Submission (s): 1129

Problem Description The really Neato Calculator Company, Inc. has recently hired the team to help design your Super their o Model I Calculator. As a computer scientist you suggested to the "company" that it would is neato if this new calculator convert could num BER bases. The company thought this is a stupendous idea and has 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 this calculator'll have the following NEA To features:
It'll 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.
Input the input for your prototype program would consist of one base conversion per line. There would be three numbers per line. The number in the base and you are converting from. The second number is the base of your are converting from. The third number is the base of your are converting to. There is one or more blanks surrounding (on either side of) the numbers. There are several lines of input and your program should continue to read until the ' end of ' file is reached.

Output the 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 number is to large to appear on the display, then print "ERROR" (without the quotes) right justified in the DISPLA Y.
Sample Input
1111000 2 1111000 2 2102101 3 2102101 3 12312 4 2 1 a 2 1234567 ABCD 16 15
Sample Output
1765 7CA ERROR 11001 12d687 D071

AC Code: Simulate the manual conversion of the system

#include <iostream> #include <cstdlib> #include <cstdio> #include <cmath> #include <cstring > #include <string> #include <cstdlib> #include <iomanip> #include <algorithm> #include <
time.h> typedef long LL;	
using namespace Std;
	int main () {char c[20];
	long int i,j,n,k,a,b,y;
		while (scanf ("%s%ld%ld", C,&a,&b)!=eof) {char s[20];
		k=0;
		N=strlen (c);  for (i=0;i<=n;++i)///convert first to decimal {if (c[i]>= ' 0 ' &&c[i]<= ' 9 ') y=c[i]-48;
				Equivalent to y=c[i]-' 0 ' else switch (C[i]) {case ' A ': y=10;break;
				Case ' B ': y=11;break;
				Case ' C ': y=12;break;
				Case ' D ': y=13;break;
				Case ' E ': y=14;break;
			Case ' F ': y=15;break; 
		} k+= (y* (LL) POW (a,n-i-1));
		} if (k==0) {printf ("0\n"); continue;}
		i=0;
			while (k)//Convert to B-system {y=k%b;  if (y>=0&&y<=9) s[i]=y+48;
				Equivalent to y=c[i]+ ' 0 ' else switch (y) {case 10:s[i]= ' A ';
	   Case 11:s[i]= ' B ';         Case 12:s[i]= ' C ';
			    Case 13:s[i]= ' D ';
				Case 14:s[i]= ' E ';
			Case 15:s[i]= ' F ';
			} k=k/b;
		i++;
		} if (i>7) printf ("ERROR");
			else {for (j=0;j<7-i;j++) printf ("");
			I=i-1;
		for (; i>=0;i--) printf ("%c", S[i]);
	printf ("\ n");
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.