• C# 针对List去重处理


     1 static public List<List<string>> DistinctList(List<List<string>> OriginalListCrpcps)
     2         {
     3             List<string> WholeFrm = new List<string>();
     4             List<List<string>> DistinctListCrpcps = new List<List<string>>();
     5             foreach (List<string> Original in OriginalListCrpcps)
     6             {
     7                 foreach (string ori in Original)
     8                 {
     9                     if (!WholeFrm.Contains(ori))
    10                     {
    11                         WholeFrm.Add(ori);
    12                     }
    13                 }
    14                 if (DistinctListCrpcps.Count() == 0)
    15                 {
    16                     DistinctListCrpcps.Add(Original);
    17                     continue;
    18                 }
    19                 bool cur = false;
    20                 foreach (List<string> Distinct in DistinctListCrpcps)
    21                 {
    22                     foreach (var Ori in Original)
    23                     {
    24                         if (!Distinct.Contains(Ori))
    25                         {
    26                             cur = true;
    27                         }
    28                     }
    29                 }
    30                 if (cur)
    31                 {
    32                     DistinctListCrpcps.Add(Original);
    33                 }
    34             }
    35             //所有的切片,如果这个切片被其他切片包含,那么删除这个切片,
    36             //这个切片里面所有的东西都在另一个切片里面
    37             List<List<string>> SimpleDistinctListCrpcps = new List<List<string>>();
    38             foreach (var Dis in DistinctListCrpcps)
    39             {
    40                 foreach (var DisOther in DistinctListCrpcps)
    41                 {
    42                     //除了本身,如果这个的所有东西都在另一个切片里面,那么这个就要删除
    43                     if ((Dis != DisOther) && (Dis.All(x => DisOther.Contains(x))))
    44                     {
    45                         SimpleDistinctListCrpcps.Add((Dis));
    46                     }
    47                 }
    48             }
    49             foreach (var sim in SimpleDistinctListCrpcps)
    50             {
    51                 DistinctListCrpcps.Remove(sim);
    52             }
    53             return DistinctListCrpcps;
    54         }
  • 相关阅读:
    BZOJ 2574: [Poi1999]Store-Keeper
    BZOJ 1024: [SCOI2009]生日快乐
    BZOJ 2541: [Ctsc2000]冰原探险
    hihoCoder 1303 数论六·模线性方程组
    Codeforces 710 D. Two Arithmetic Progressions
    BZOJ 1670: [Usaco2006 Oct]Building the Moat护城河的挖掘
    ZJOI2014 2048
    51Nod 1766 树上的最远点对
    Codeforces 727 F. Polycarp's problems
    BZOJ 3736: [Pa2013]Karty
  • 原文地址:https://www.cnblogs.com/smartisn/p/16331942.html
Copyright © 2020-2023  润新知