Problem Description
The 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.
Input
The 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.
Output
The output would is only being 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 display .
Sample Input
1111000 2101111000 2162102101 3102102101 315 12312 4 2 1A15 212345671016 1615
Sample Output
120 78 1765 7CA ERROR 1100112D687 D071
Input 3 number: N a B
The input n is the number of a, which requires the conversion of N to the number of the B-binary.
If the number of digits after the conversion exceeds 7, the ERROR is output.
Each output occupies 7 bits, and less than 7 bits of left fill space.
Import Java.util.Scanner; Public classmain{ Public Static void Main(string[] args) {Scanner SC =NewScanner (System.inch); while(Sc.hasnext ()) {String strnum = Sc.next ();intA = Sc.nextint ();intb = Sc.nextint ();ints = integer.valueof (Strnum, a);//Convert the Strnum of a into 10 binary sString Snum = integer.tostring (s, b);if(Snum.length () >7) {System. out. println ("ERROR");Continue; } for(intI=7; I>snum.length (); i--) {System. out. Print (" "); } System. out. println (Snum.touppercase ()); } }}
Hdoj 1335 basically Speaking (in-process conversion)