车牌号寓意分析与评分类

/// <summary>
/// 车牌号寓意分析与评分类(基于传统文化优化规则)
/// </summary>
public static class LicensePlateAnalyzer
{
    // 1. 单个数字评分(正数为加分,负数为扣分,符合中国人对数字的偏好)
    private static readonly Dictionary<char, int> _numberScores = new Dictionary<char, int>()
        {
            {'0', 4},  // 圆满、起点
            {'1', 6},  // 一帆风顺、第一
            {'2', 5},  // 成双成对、好事成双
            {'3', 3},  // 三生有幸(中性偏吉)
            {'4', -8}, // 谐音“死”(不吉)
            {'5', 5},  // 五福临门、五谷丰登
            {'6', 8},  // 六六大顺(吉)
            {'7', 2},  // 中性(部分地区视为“起”,少量加分)
            {'8', 10}, // 谐音“发”(极吉)
            {'9', 9}   // 长长久久、九五之尊(极吉)
        };

    // 2. 单个字母评分(排除易混淆字母I/O,中性为主,特殊字母加分)
    private static readonly Dictionary<char, int> _letterScores = new Dictionary<char, int>()
        {
            {'A', 6}, {'B', 4}, {'C', 4}, {'D', 3}, {'E', 5}, {'F', 3}, {'G', 3}, {'H', 5},
            {'J', 4}, {'K', 3}, {'L', 3}, {'M', 5}, {'N', 4}, {'P', 4}, {'Q', 2}, {'R', 3},
            {'S', 6}, {'T', 3}, {'U', 3}, {'V', 3}, {'W', 5}, {'X', 2}, {'Y', 5}, {'Z', 4}
        };

    // 3. 吉利组合额外加分(如888、168等)
    private static readonly Dictionary<string, int> _luckyCombinations = new Dictionary<string, int>()
        {
            {"66", 15}, {"88", 25}, {"99", 20}, {"68", 20}, {"86", 20}, {"168", 40},
            {"666", 50}, {"888", 70}, {"999", 60}, {"111", 20}, {"222", 20}, {"555", 20},
            {"123", 30}, {"321", 25}, {"789", 30} // 顺子组合
        };

    // 4. 不吉利组合额外扣分(如444、74等)
    private static readonly Dictionary<string, int> _unluckyCombinations = new Dictionary<string, int>()
        {
            {"44", -20}, {"74", -30}, {"47", -30}, {"444", -60}, {"64", -15}, {"46", -15}
        };

    /// <summary>
    /// 分析车牌号并返回评分(0-100+,分数越高寓意越好)
    /// </summary>
    public static int Analyze(string licensePlate)
    {
        if (string.IsNullOrEmpty(licensePlate) || licensePlate.Length != 7)
            return 0;

        int totalScore = 0;
        string plateBody = licensePlate.Substring(1); // 去掉省份简称,只分析后6位(字母+5位字符)

        // 1. 单个字符评分(字母+数字)
        foreach (char c in plateBody)
        {
            if (char.IsDigit(c) && _numberScores.ContainsKey(c))
                totalScore += _numberScores[c];
            else if (char.IsLetter(c) && _letterScores.ContainsKey(char.ToUpper(c)))
                totalScore += _letterScores[char.ToUpper(c)];
        }

        // 2. 双字符组合评分
        for (int i = 0; i < plateBody.Length - 1; i++)
        {
            string pair = plateBody.Substring(i, 2);
            if (_luckyCombinations.ContainsKey(pair))
                totalScore += _luckyCombinations[pair];
            if (_unluckyCombinations.ContainsKey(pair))
                totalScore += _unluckyCombinations[pair];
        }

        // 3. 三字符组合评分(重点加分项)
        for (int i = 0; i < plateBody.Length - 2; i++)
        {
            string triple = plateBody.Substring(i, 3);
            if (_luckyCombinations.ContainsKey(triple))
                totalScore += _luckyCombinations[triple];
            if (_unluckyCombinations.ContainsKey(triple))
                totalScore += _unluckyCombinations[triple];
        }

        // 确保最低分为0(避免负分)
        return Math.Max(totalScore, 0);
    }
}
posted @ 2025-08-29 17:27  我的名字长沙雕跟着念  阅读(42)  评论(0)    收藏  举报