Algorithm Note _225: Digital cipher Generator (Java)

Source: Internet
Author: User
Tags stringbuffer

Directory

1 Problem Description

2 Solutions

  1 problem description

In the bank account and other important permissions to set the password, we often encounter such a problem: if you want to remember the birthday, easy to be cracked, unsafe, if you set a bad password, but also worried that they will forget, if written on paper, worried that the paper was found or lost ...

The task of this program is to convert a string of phonetic Alphabet to a 6-digit number (password). We can use any well-remembered pinyin string (such as name, Wang Ximing, write: wangximing) as input, the program output 6 digits.

The process of transformation is as follows:

The first step. Fold the string 6 a group, for example, wangximing into:
Wangxi
Ming

The second step. The ASCII values of all characters perpendicular to the same position are added, resulting in 6 numbers, as shown in the example above:
228 202 220 206 120 105

The third step. Then the number of each digit "indent" Processing: is to add the number of each bit, the figure if it is not a number, and then shrink, until it becomes a digit. For example: 228 = 2+2+8=12 = 1+2=3

The above number is reduced to: 344836, which is the final output of the program!

Requires the program to receive data from the standard input and output the results on the standard output.

The input format is: The first line is an integer n (<100), which indicates how many input rows are below, followed by n-line strings, or strings waiting to be transformed.
The output format is: N-line 6-bit password after transformation.

For example, enter:
5
Zhangfeng
Wangximing
Jiujingfazi
Woaibeijingtiananmen
Haohaoxuexi

The output:
772243
344836
297332
716652
875843

Attention:

Please carefully debug! Your program only has the chance to score when it can run the correct results!

The input data used in the grading is probably different from the instance data given in the quiz paper.

2 Solutions

1 Importjava.util.ArrayList;2 ImportJava.util.Scanner;3 4  Public classMain {5      Public Staticarraylist<string> list =NewArraylist<string>();6     7      Publicstring GetResult (string s) {8         int[] A =New int[6];9          for(inti = 0;i < S.length (); i++)TenA[i% 6] = a[i% 6] +S.charat (i); One          for(inti = 0;i < 6;i++) { A              while(A[i] >= 10) { -String temp = "" +A[i]; -                 intA = 0; the                  for(intj = 0;j < Temp.length (); j + +) -A = A + (Temp.charat (j)-' 0 '); -A[i] =A; -             } +         } -StringBuffer T =NewStringBuffer (""); +          for(inti = 0;i < 6;i++) A t.append (A[i]); at         returnt.tostring (); -     } -      -      Public Static voidMain (string[] args) { -Main test =NewMain (); -Scanner in =NewScanner (system.in); in         intn =in.nextint (); -          for(inti = 0;i < n;i++) { toString s =In.next (); + List.add (Test.getresult (s)); -         } the          for(inti = 0;i < n;i++) * System.out.println (List.get (i)); $     }Panax Notoginseng}

Operation Result:

3woainisaibeidexuetiaotiaodalutongluomaxyz137563848586345000

Algorithm Note _225: Digital cipher Generator (Java)

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.