Mobile phone number rating

30 years of reform and opening up have brought earth-shaking changes to China. In 2011, China's mobile phone output was about 1.172 billion units. Mobile phones have become the basic daily necessities of the people! Choosing a nice and memorable number for your mobile phone may be the wish of many people.
However, the number source is limited, and it can only be supplemented by the method of paid number selection.
The purpose of this program is: according to the given mobile phone tail number (4 digits), according to certain rules to score. The rules are as follows:
1. If there are consecutive numbers, regardless of ascending or descending order, 5 points will be added. For example: 5678, 4321 all meet the bonus criteria.
2. If the first three numbers are the same, or the last three numbers are the same, 3 points will be added. For example: 4888, 6665, 7777 all meet the criteria for bonus points.
Note: 7777 is awarded 6 points by this rule because it meets this criterion twice.
3. Add 1 point for those who conform to the AABB or ABAB model. For example: 2255, 3939, 7777 all conform to this pattern, so they are all added points.
Note: 7777 has 2 points for this criterion because it met this criterion twice.
4. Contain: 6, 8, 9 any one of the numbers, add 1 point for each occurrence. For example, 4326, 6875, 9918 all meet the bonus criteria. Among them, 6875 were added 2 points; 9918 were added 3 points.
The final score of the tail number is the sum of the bonus points for each criterion!
The program is required to receive data from standard input and output results on standard output.
The input format is: the first line is an integer n (<100), indicating how many input lines there are below, followed by n lines of 4-bit data, which is the end number of the mobile phone waiting to calculate the extra points.
For example, input:
14
3045
....
.....
6789
8866
and output:
0
0
….

8
5
core code:

    mport java.util.Scanner;
    import java.util.Stack;
    import java.util.Vector;
    public class Question5 {
        public static void main(String[] args) {
            Scanner scanner=new Scanner(System.in);
            int n=scanner.nextInt();
            scanner.nextLine();
            while ((n--)>0) {
                String telphone=scanner.nextLine();
                int sum=0;
                /*
                 * 情况一
                 */
                if(telphone.charAt(0)-telphone.charAt(1)==1){
                    char ch=telphone.charAt(0);
                    int index=0;
                    while (index<4&&ch==telphone.charAt(index)) {
                        ch--;
                        index++;
                    }
                    if(index>=4){
                        sum+=5;
                    }
                }
                if (telphone.charAt(0)-telphone.charAt(1)==-1) {
                    char ch=telphone.charAt(0);
                    int index=0;
                    while (index<4&&ch==telphone.charAt(index)) {
                        ch++;
                        index++;
                    }
                    if(index>=4){
                        sum+=5;
                    }
                }
                /*
                 * 情况二
                 */
                if (telphone.charAt(0)==telphone.charAt(1)&&telphone.charAt(1)==telphone.charAt(2)) {
                    sum+=3;
                }
                if(telphone.charAt(1)==telphone.charAt(2)&&telphone.charAt(2)==telphone.charAt(3)){
                    sum+=3;
                }

                /*
                 * 情况三
                 */
                if(telphone.charAt(0)==telphone.charAt(1)&&telphone.charAt(2)==telphone.charAt(3)){
                    sum+=1;
                }
                if(telphone.charAt(0)==telphone.charAt(2)&&telphone.charAt(1)==telphone.charAt(3)){
                    sum+=1;
                }
                /*
                 * 情况四
                 */
                for (int i = 0; i < 4; i++) {
                    if(telphone.charAt(i)=='6'||telphone.charAt(i)=='8'||telphone.charAt(i)=='9'){
                        sum+=1;
                    }
                }
                System.out.println(sum);
            }
        }
    }

Running result:
14
3045
0211
 …
..
 …
8
5

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324593937&siteId=291194637