Problem:
Conversion between characters in C can be in Char A=char (b+5), but in Java it is useless, here is a conversion method: int C=b+5;char A=char (c);
string strings, upside down:
Stringbffer str=new StringBuffer (s);
S=str.reverse (). toString ();
In the test added some output statements, and some small changes, in the output forget to change back, leading to not pass, please note!!!
Binary conversionTime limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 30858 Accepted Submission (s): 17147
Problem description Enter a decimal number n to convert it to the R-binary output.
Input data contains multiple test instances, each containing two integer n (32-bit integers) and R (2<=r<=16, r<>10).
Output outputs the converted number for each test instance, with one row for each output. If R is greater than 10, then the corresponding number rules refer to 16 binary (for example, 10 is represented by a, and so on).
Sample Input
7 223 12-4 3
Sample Output
1111b-11
Code:
Import java.util.*;p ublic class main{public static void Main (String args[]) {Scanner cin=new Scanner (system.in); while ( Cin.hasnext ()) {int n=cin.nextint (); int r=cin.nextint (); String s= ""; if (n<0) {n=-n; System.out.print ("-");} Char a= ' a '; int b=a;while (n>0) {int t=n%r;if (t>=10) {int C=t-10+b;char d= (char) c;s=s+d;} ELSES=S+T;N=N/R;} StringBuffer str=new StringBuffer (s); S=str.reverse (). toString (); System.out.println (str);}}}
HDU 2031 Binary conversion (Java)