First, let's look at a programming topic:
A divided by B (20) time limit MS Memory limit 32768 KB code length limit (from small) to Judge programTitle Description
The subject requires a A/b, where A is a positive integer that does not exceed 1000 bits, and B is a 1-bit positive integer. You need to output the quotient Q and the remainder r so that a = B * Q + R is set up.
Input Description:
The input is given a and B in 1 rows, and the middle is separated by 1 spaces.
Output Description:
In 1 rows, output Q and R in turn, separated by 1 spaces in the middle.
Input Example:
123456789050987654321 7
Output Example:
17636684150141093474 3
Requirements: With Java to complete, I believe a lot of people can use c a few minutes to complete, but, if you are a Java novice, when you just read the topic, feel very simple, you often will skip,
But the knowledge contained therein may not be understood by you.
I would like to say my problem-solving ideas: Using string string to complete, just do, caught in the beginning of the 0 vortex, then think, you can first 0 save, the final output of the time to deal with.
The implementation code is as follows:
Package package11;
Import Java.util.Scanner;
public class Main
{
public static void Main (String []args)
{
Scanner cin = new Scanner (system.in);
String str;
String output = "";
int n;
int re;
str = Cin.next ();
n = cin.nextint ();
int len = Str.length ();
int k = 0;
int num;
for (int i = 0; i < len; i++)
{
num = integer.valueof (string.valueof (Str.charat (i)));
num + = k*10;
if (num/n! = 0)
{
Output + = string.valueof (num/n);
K = num%n;
}
Else
{
Output + = "0";
k = num;
}
}
int len1 = Output.length ();
int cnt = 0;
for (int i = 0; i < len1; i++)
{
if (cnt = = 0 && Output.charat (i) = = ' 0 ')
{
Continue
}
Else
{
System.out.print (Output.charat (i));
CNT = 1;
}
}
System.out.print ("" + K);
}
}
In fact: As long as you know the basic knowledge, it will be quickly made, but if you do not understand, it must be very laborious.
I'm talking about some string knowledge:
Conversion between string and int
String converted to Int:Integer.valueOf ("12")//Remember that the inside is a string, not a single character.
int converted to STRING:STRING.VALUEOF (12)
Conversion between char and int
Convert char to string first
String str=string.valueof (' 2 ')
Integer.valueof (str) or integer.paseint (str)
Integer.valueof returns an Integer object, Integer.paseint returns an int
Note: System.out.println (integer.valueof (' 9 ')); The result is: 57
System.out.print (integer.valueof ("9")); the result is: 9
Java, numbers, characters, conversions between strings