3

例如,我有以下数据:

YELLOW,SMALL,STRETCH,ADULT,T
YELLOW,SMALL,STRETCH,ADULT,T
YELLOW,SMALL,STRETCH,CHILD,F
YELLOW,SMALL,DIP,ADULT,F
YELLOW,SMALL,DIP,CHILD,F
YELLOW,LARGE,STRETCH,ADULT,T
YELLOW,LARGE,STRETCH,ADULT,T
YELLOW,LARGE,STRETCH,CHILD,F
YELLOW,LARGE,DIP,ADULT,F
YELLOW,LARGE,DIP,CHILD,F
PURPLE,SMALL,STRETCH,ADULT,T
PURPLE,SMALL,STRETCH,ADULT,T
PURPLE,SMALL,STRETCH,CHILD,F
PURPLE,SMALL,DIP,ADULT,F
PURPLE,SMALL,DIP,CHILD,F
PURPLE,LARGE,STRETCH,ADULT,T
PURPLE,LARGE,STRETCH,ADULT,T
PURPLE,LARGE,STRETCH,CHILD,F
PURPLE,LARGE,DIP,ADULT,F
PURPLE,LARGE,DIP,CHILD,F

我需要生成以下几组数据(注意上面数据的列会生成下面的数据个数)如果有5列,就会有4组数据,第一个单列,第二个2个,第三个3个,等等。最后一列被省略,是连接所有数据的 CLASS 列,数字是它在上述给定数据中的出现次数。

--------------------------------------------------
1 column
--------------------------------------------------
YELLOW  T   4   
SMALL   T   4   
STRETCH T   8   
ADULT   T   8   
YELLOW  F   6   
SMALL   F   6   
STRETCH F   4   
CHILD   F   8   
DIP F   8   
ADULT   F   4   
LARGE   T   4   
LARGE   F   6   
PURPLE  T   4   
PURPLE  F   6   
--------------------------------------------------
2 columns
--------------------------------------------------
YELLOW  SMALL   T   2   
YELLOW  STRETCH T   4   
YELLOW  ADULT   T   4   
SMALL   STRETCH T   4   
SMALL   ADULT   T   4   
STRETCH ADULT   T   8   
YELLOW  SMALL   F   3   
YELLOW  STRETCH F   2   
YELLOW  CHILD   F   4   
SMALL   STRETCH F   2   
SMALL   CHILD   F   4   
STRETCH CHILD   F   4   
YELLOW  DIP F   4   
YELLOW  ADULT   F   2   
SMALL   DIP F   4   
SMALL   ADULT   F   2   
DIP ADULT   F   4   
DIP CHILD   F   4   
YELLOW  LARGE   T   2   
LARGE   STRETCH T   4   
LARGE   ADULT   T   4   
YELLOW  LARGE   F   3   
LARGE   STRETCH F   2   
LARGE   CHILD   F   4   
LARGE   DIP F   4   
LARGE   ADULT   F   2   
PURPLE  SMALL   T   2   
PURPLE  STRETCH T   4   
PURPLE  ADULT   T   4   
PURPLE  SMALL   F   3   
PURPLE  STRETCH F   2   
PURPLE  CHILD   F   4   
PURPLE  DIP F   4   
PURPLE  ADULT   F   2   
PURPLE  LARGE   T   2   
PURPLE  LARGE   F   3
--------------------------------------------------
3 columns
--------------------------------------------------
YELLOW  SMALL   STRETCH T   2   
YELLOW  SMALL   ADULT   T   2   
YELLOW  STRETCH ADULT   T   4   
SMALL   STRETCH ADULT   T   4   
YELLOW  SMALL   STRETCH F   1   
YELLOW  SMALL   CHILD   F   2   
YELLOW  STRETCH CHILD   F   2   
SMALL   STRETCH CHILD   F   2   
YELLOW  SMALL   DIP F   2   
YELLOW  SMALL   ADULT   F   1   
YELLOW  DIP ADULT   F   2   
SMALL   DIP ADULT   F   2   
YELLOW  DIP CHILD   F   2   
SMALL   DIP CHILD   F   2   
YELLOW  LARGE   STRETCH T   2   
YELLOW  LARGE   ADULT   T   2   
LARGE   STRETCH ADULT   T   4   
YELLOW  LARGE   STRETCH F   1   
YELLOW  LARGE   CHILD   F   2   
LARGE   STRETCH CHILD   F   2   
YELLOW  LARGE   DIP F   2   
YELLOW  LARGE   ADULT   F   1   
LARGE   DIP ADULT   F   2   
LARGE   DIP CHILD   F   2   
PURPLE  SMALL   STRETCH T   2   
PURPLE  SMALL   ADULT   T   2   
PURPLE  STRETCH ADULT   T   4   
PURPLE  SMALL   STRETCH F   1   
PURPLE  SMALL   CHILD   F   2   
PURPLE  STRETCH CHILD   F   2   
PURPLE  SMALL   DIP F   2   
PURPLE  SMALL   ADULT   F   1   
PURPLE  DIP ADULT   F   2   
PURPLE  DIP CHILD   F   2   
PURPLE  LARGE   STRETCH T   2   
PURPLE  LARGE   ADULT   T   2   
PURPLE  LARGE   STRETCH F   1   
PURPLE  LARGE   CHILD   F   2   
PURPLE  LARGE   DIP F   2   
PURPLE  LARGE   ADULT   F   1   
--------------------------------------------------
4 columns
--------------------------------------------------
YELLOW  SMALL   STRETCH ADULT   T   2   
YELLOW  SMALL   STRETCH CHILD   F   1   
YELLOW  SMALL   DIP ADULT   F   1   
YELLOW  SMALL   DIP CHILD   F   1   
YELLOW  LARGE   STRETCH ADULT   T   2   
YELLOW  LARGE   STRETCH CHILD   F   1   
YELLOW  LARGE   DIP ADULT   F   1   
YELLOW  LARGE   DIP CHILD   F   1   
PURPLE  SMALL   STRETCH ADULT   T   2   
PURPLE  SMALL   STRETCH CHILD   F   1   
PURPLE  SMALL   DIP ADULT   F   1   
PURPLE  SMALL   DIP CHILD   F   1   
PURPLE  LARGE   STRETCH ADULT   T   2   
PURPLE  LARGE   STRETCH CHILD   F   1   
PURPLE  LARGE   DIP ADULT   F   1   
PURPLE  LARGE   DIP CHILD   F   1   

所以甚至可以有 50 列,也可以有 80 甚至更多。

复杂性还在于可以有 0 和 1 而不是单词,我们需要匹配相同的列。

希望你有这个问题。

我制作了以下代码来生成第一列。主要问题是其余列。

for (int i = 0; i < lsClasses.Count; i++)
            {
                for (int j = 0; j < lsUniqueOps.Count; j++)
                {
                    int count = FindInOrignalList(orignalList, lsClasses[i], lsUniqueOps[j]);
                    if (count != 0)
                    {
                        List<string> checkedItem = new List<string>();
                        checkedItem.Add(lsUniqueOps[j][0]);
                        checkedItem.Add(lsUniqueOps[j][1]);
                        checkedItem.Add(lsClasses[i]);
                        checkedItem.Add(count.ToString());
                        lsFirstItemSet.Add(checkedItem);
                    }
                }
            }

--------------------------------------------------

private static int FindInOrignalList(List<List<string>> orignalList, string lsClass, List<string> lsUniqueOp)
        {
            List<List<string>> tmpList = new List<List<string>>();
            int count = 0;
            for (int i = 0; i < orignalList.Count; i++)
            {
                for (int j = 0; j < orignalList[i].Count - 1; j++)
                {
                    if (orignalList[i][j] + "," + orignalList[i][orignalList[i].Count - 1] == lsUniqueOp[0] + "," + lsClass)
                        count++;
                }
            }
            return count;
        }
4

1 回答 1

0

如果我没看错,你只列出最后没有“F”的市场事件。你只会得到“T”。那是对的吗?如果是这样,您可以从

  1. 删除 F'ed 的行,因为它们永远不会导致任何上升,
  2. 完全删除最后一列(因为只有 T 存在并且一行的存在已经暗示了它的真实性)
  3. 告诉我这是否是一项家庭作业(在这种情况下,您处于初级水平,需要与高级程序员不同的解释)。

我会假设你是精明的类型。然后,您可以应用 LINQ 和合适的数据结构来计算出现次数。就在我的脑海中 -DataSet和公司可能是一个不错的选择。Dictionary可能是另一个。

于 2012-09-28T09:08:42.520 回答