zoukankan      html  css  js  c++  java
  • java实现手机尾号评分

    30年的改革开放,给中国带来了翻天覆地的变化。2011全年中国手机产量约为11.72亿部。手机已经成为百姓的基本日用品!

    给手机选个好听又好记的号码可能是许多人的心愿。但号源有限,只能辅以有偿选号的方法了。

    这个程序的目的就是:根据给定的手机尾号(4位),按照一定的规则来打分。其规则如下:

    1. 如果出现连号,不管升序还是降序,都加5分。例如:5678,4321都满足加分标准。

    2. 前三个数字相同,或后三个数字相同,都加3分。例如:4888,6665,7777都满足加分的标准。注意:7777因为满足这条标准两次,所以这条规则给它加了6分。

    3. 符合AABB或者ABAB模式的加1分。例如:2255,3939,7777都符合这个模式,所以都被加分。注意:7777因为满足这条标准两次,所以这条标准给它加了2分。

    4. 含有:6,8,9中任何一个数字,每出现一次加1分。例如4326,6875,9918都符合加分标准。其中,6875被加2分;9918被加3分。

    尾号最终得分就是每条标准的加分总和!

    要求程序从标准输入接收数据,在标准输出上输出结果。

    输入格式为:第一行是一个整数n(<100),表示下边有多少输入行,接下来是n行4位一组的数据,就是等待计算加分的手机尾号。
    输出格式为:n行整数。
    例如,输入:
    14
    3045
    0211
    2345
    6543
    7777
    8888
    7878
    7788
    6688
    2424
    2244
    9918
    6789
    8866
    则输出:
    0
    0
    5
    6
    8
    12
    3
    3
    5
    1
    1
    3
    8
    5

    注意:

    请仔细调试!您的程序只有能运行出正确结果的时候才有机会得分!
    在评卷时使用的输入数据与试卷中给出的实例数据可能是不同的。

    package com.liu.ex10;
    
    import java.util.ArrayList;
    import java.util.Scanner;
    
    
    public class Main {
        
        public int getScore(String A) {
            int count = 0;
            ArrayList<Integer> list = new ArrayList<Integer>();
            for(int i = 0;i < A.length();i++) {
                int a = A.charAt(i) - '0';
                list.add(a);
            }
            //规则1
            int i = 1;
            for(;i < 4;i++) {
                if(list.get(i) == list.get(i - 1) + 1)
                    continue;
                else
                    break;
            }
            if(i == 4)
                count = count + 5;
            for(i = 1;i < 4;i++) {
                if(list.get(i) == list.get(i - 1) - 1)
                    continue;
                else
                    break;
            }
            if(i == 4)
                count = count + 5;
            //规则2
            int a1 = list.get(0), a2 = list.get(1), a3 = list.get(2), a4 = list.get(3);
            if(a1 == a2 && a1 == a3)
                count = count + 3;
            if(a2 == a3 && a2 == a4)
                count = count + 3;
            //规则3
            if(a1 == a2 && a3 == a4)
                count = count + 1;
            if(a1 == a3 && a2 == a4)
                count = count + 1;
            //规则4
            for(i = 0;i < 4;i++) {
                if(list.get(i) == 6 || list.get(i) == 8 || list.get(i) == 9)
                    count = count + 1;
            }
            return count;
        }
        
        public void printResult(String[] arrayA) {
            int[] result = new int[arrayA.length];
            for(int i = 0;i < arrayA.length;i++) {
                int temp = getScore(arrayA[i]);
                result[i] = temp;
            }
            for(int i = 0;i < result.length;i++)
                System.out.println(result[i]);
            return;
        }
        
        public static void main(String[] args) {
            Main test = new Main();
            Scanner in = new Scanner(System.in);
            int n = in.nextInt();
            in.nextLine();
            String[] arrayA = new String[n];
            for(int i = 0;i < n;i++)
                arrayA[i] = in.nextLine();
            test.printResult(arrayA);
        }
    }
    
  • 相关阅读:
    ubuntu操作技巧
    电机
    哈佛结构与冯若依曼结构
    linux command ------ ls
    Frames of Reference参考框架
    What Are Tango Poses?Tango姿态是什么?
    Google Tango Java SDK开发:Motion Tracking 运动追踪
    Google Tango Java SDK开发:Configure and Connect 配置和连接
    gradle
    Google Tango service outdated谷歌Tango的服务过时了
  • 原文地址:https://www.cnblogs.com/a1439775520/p/13077817.html
Copyright © 2011-2022 走看看