新手入门求大神们指点🙏

img

img

#include <iostream>
using namespace std;
int main()
{
    const string pyh = "潘阳湖";
    const string dth = "洞庭湖";
    const string th = "太湖";
    const string hzh = "洪泽湖";
    
    string a[4] = {dth,th,pyh,hzh};
    string b[4] = {hzh,pyh,th,dth};
    string c1[4] = {th,pyh,dth,hzh};
    string c2[4] = {pyh,th,dth,hzh};
    string d[4] = {pyh,hzh,dth,th};
    
    string array[4] = {pyh, dth, th, hzh};
    string result[4];
    
    for (int i = 0; i < 4; i ++)
    {
        result[0] = array[i];
        for (int j = 0; j < 4; j ++)
        {
            if (i == j)continue;
            result[1] = array[j];
            for (int k = 0; k < 4; k ++)
            {
                if (i == k || j == k)continue;
                result[2] = array[k];
                for (int l = 0; l < 4; l ++)
                {
                    if (i ==l || j == l || k == l)continue;
                    result[3] = array[l];
                    
                    int aint = (a[i] == result[i]) + (a[j] == result[j]) + (a[k] == result[k]) + (a[l] == result[l]);
                    int bint = (b[i] == result[i]) + (b[j] == result[j]) + (b[k] == result[k]) + (b[l] == result[l]);
                    int c1int = (c1[i] == result[i]) + (c1[j] == result[j]) + (c1[k] == result[k]) + (c1[l] == result[l]);
                    int c2int = (c2[i] == result[i]) + (c2[j] == result[j]) + (c2[k] == result[k]) + (c2[l] == result[l]);
                    int dint = (c2[i] == result[i]) + (d[j] == result[j]) + (d[k] == result[k]) + (d[l] == result[l]);

                    if (aint == 1 && bint == 1 && (c1int == 1 || c2int == 1) && dint == 1)
                    {
                        cout<<i<<j<<k<<l<<endl;                        
                        cout<<result[i]<<result[j]<<result[k]<<result[l]<<endl;
                    }
                    
                }
            }
        }
    }
}

用笨办法实现了一大部分,懒得弄答案正确项数量验证了,c#代码


        static void Main(string[] args)
        {
            #region 初始化所有人的答案
            List<string[]> an = new List<string[]>();
            an.Add(new string[] { "洞庭湖:1", "洪泽湖:4", "鄱阳湖:3" });
            an.Add(new string[] { "洪泽湖:1", "洞庭湖:4", "鄱阳湖:2", "太湖:3" });
            an.Add(new string[] { "洪泽湖:4", "洞庭湖:3" });
            an.Add(new string[] { "洪泽湖:2", "洞庭湖:3", "鄱阳湖:1", "太湖:4" });
            #endregion
            #region 获得所有答案组合
            List<string[]> aw = checkAnswer(an);
            #endregion
            #region 验证所有不冲突的答案
            List<string[]> cfm = new List<string[]>();
            for (int i = 0; i < aw.Count; i++)
            {
                bool invalid = false;
                Dictionary<string, string> d = new Dictionary<string, string>();
                for (int j = 0; j < aw[i].Length; j++)
                {
                    string[] t = aw[i][j].Split(new string[] { ":" }, StringSplitOptions.None);
                    if (!d.ContainsKey(t[0]))
                    {
                        if (!d.ContainsValue(t[1]))
                        {
                            d.Add(t[0], t[1]);
                        }
                        else
                        {
                            invalid = true;
                            break;
                        }
                    }
                    else
                    {
                        if (d[t[0]] != t[1])
                        {
                            invalid = true;
                            break;
                        }
                    }
                }
                if (!invalid)
                {
                    cfm.Add(aw[i]);
                }
            }
            #endregion
            if (cfm.Count == 0)
            {
                Console.Write("没有正确答案");
            }
            else
            {
                #region 验证所有成立的答案中,是否存在某个回答出现了多个正确项
                Dictionary<string, List<string[]>> final = new Dictionary<string, List<string[]>>();
                string[] h = "洞庭湖,洪泽湖,太湖,鄱阳湖".Split(new string[] { "," }, StringSplitOptions.None);
                for (int i = 0; i < cfm.Count; i++)
                {
                    List<string> p = new List<string>();
                    p.AddRange(new string[4]);
                    for (int j = 0; j < cfm[i].Length; j++)
                    {
                        string[] x = cfm[i][j].Split(new string[] { ":" }, StringSplitOptions.None);
                        p[int.Parse(x[1]) - 1] = x[0];
                    }
                    for (int j = 0; j < h.Length; j++)
                    {
                        if (!p.Contains(h[j]))
                        {
                            for (int k = 0; k < p.Count; k++)
                            {
                                if (string.IsNullOrEmpty(p[k]))
                                {
                                    p[k] = h[j];
                                    break;
                                }
                            }
                        }
                    }
                    // 请自行在此添加所有人答案中,正确项的数量
                    string pi = String.Join(",", p.ToArray());
                    if (!final.ContainsKey(pi))
                    {
                        final.Add(pi, new List<string[]>());
                    }
                    final[pi].Add(cfm[i]);
                }
                foreach (string k in final.Keys)
                {
                    List<string[]> p = final[k];
                    if (p.Count == 1)
                    {
                        Console.WriteLine("回答结果:" + String.Join(",", p[0].ToArray()));
                        Console.WriteLine("排序结果:" + k);
                    }
                }
                #endregion
            }
            Console.ReadKey();
        }
        private static List<string[]> checkAnswer(List<string[]> an)
        {
            List<string[]> r = new List<string[]>();
            #region 使用递归,将所有人的答案进行组合
            string[] x = an[0];
            an.RemoveAt(0);
            if (an.Count == 0)
            {
                for (int i = 0; i < x.Length; i++)
                {
                    r.Add(new string[] { x[i] });
                }
            }
            else
            {
                List<string[]> r1 = checkAnswer(an);
                for (int i = 0; i < x.Length; i++)
                {
                    for (int j = 0; j < r1.Count; j++)
                    {
                        List<string> t = new List<string>();
                        t.Add(x[i]);
                        t.AddRange(r1[j]);
                        r.Add(t.ToArray());
                    }
                }
            }
            #endregion
            return r;
        }