Waterloo Cup: Basic practice of Special palindrome number

Source: Internet
Author: User

Basic Practice Special Palindrome number time limit: 1.0s memory Limit: 512.0MB problem description 123321 is a very special number, which reads from the left and reads the same from the right.
Enter a positive integer n, programming all such five-bit and six-bit decimal digits, satisfying the sum of the numbers equals N. Enter a row for the input format, including a positive integer n. The output format outputs an integer that satisfies the condition in a small to large order, and each integer occupies one row. Example input 52 sample output 899998
989989
998899 Data Scale and convention 1<=n<=54. Method of solving Problems: Set loop (10000->1000000), get the number of bits per digit, and compare the number of numbers entered. Converts a loop variable to a character array, reverse it, get a new string, and compare it to the original string (palindrome number if true). If the comparison results are true, the number of this palindrome is output.

Import Java.util.Scanner;

public class main{public

	static void Main (string[] args) {
		Scanner sc = new Scanner (system.in);
		int number = Sc.nextint ();
		int i,j,len,n;
		int sumt = 0;
		char []array = new char[6];
		String strorigin = "";
		String Strturn = "";
		StringBuilder Stbturn = new StringBuilder ();
		for (i = 10000 i < 1000000; i++) {
			n = i;
			Strorigin = integer.tostring (i);
			Array = Strorigin.tochararray ();
			while (n > 0) {
				sumt + = n%;
				n = n/10;
			}
			len = array.length;
			for (j = len-1 J >= 0; j--) {
				stbturn.append (array[j]);
			Strturn = Stbturn.tostring ();
			if (Strorigin.equals (Strturn)) {
				if (sumt = number) {
					System.out.println (i);
				}
			}
			Stbturn = new StringBuilder ();
			SUMT = 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.