本文整理汇总了C#中SortedDictionary.ContainsValue方法的典型用法代码示例。如果您正苦于以下问题:C# SortedDictionary.ContainsValue方法的具体用法?C# SortedDictionary.ContainsValue怎么用?C# SortedDictionary.ContainsValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SortedDictionary
的用法示例。
在下文中一共展示了SortedDictionary.ContainsValue方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Bfs
private static void Bfs(Dictionary<string, List<string>> graph, List<string> startingIndexes, SortedDictionary<string, int> distances)
{
Queue<string> queue = new Queue<string>();
for (int i = 0; i < startingIndexes.Count; i++)
{
queue.Enqueue(startingIndexes[i]);
distances[startingIndexes[i]] = 0;
}
while (queue.Count > 0)
{
string currentIndex = queue.Dequeue();
foreach (var child in graph[currentIndex])
{
if (distances[child] == -1)
{
distances[child] = distances[currentIndex] + 1;
queue.Enqueue(child);
}
}
}
if (distances.ContainsValue(-1))
{
Console.WriteLine("Cannot reach: {0}", string.Join(", ", distances.Keys.Where(x => distances[x] == -1).ToList()));
}
else
{
int maxSteps = distances.Values.Max();
Console.WriteLine("All people reached in {0} steps", maxSteps);
Console.WriteLine("People at last step: {0}", string.Join(", ", distances.Keys.Where(x => distances[x] == maxSteps)));
}
}
示例2: GetShortestPath
public NavPoint[] GetShortestPath(NavPoint start, NavPoint target)
{
HashSet<NavPoint> visited = new HashSet<NavPoint>();
SortedDictionary<float,NavPoint> pq = new SortedDictionary<float, NavPoint>();
Dictionary<NavPoint,NavPoint> cameFrom = new Dictionary<NavPoint, NavPoint>();
Dictionary<NavPoint,float> scores = new Dictionary<NavPoint, float>();
pq.Add(Vector3.Distance(target.position,start.position),start);
scores.Add(start,Vector3.Distance(target.position,start.position));
while(pq.Count > 0)
{
SortedDictionary<float,NavPoint>.KeyCollection.Enumerator keyEnumer = pq.Keys.GetEnumerator();
keyEnumer.MoveNext();
NavPoint np = pq[keyEnumer.Current];
pq.Remove(keyEnumer.Current);
if(IsGoal(np, target))
return ReconstructPath(cameFrom,np);
visited.Add(np);
foreach(NavPoint neighbour in np.neighbours)
{
if(neighbour.gameObject.activeInHierarchy)
{
if(visited.Contains(neighbour))
continue;
float estimate = scores[np] + Vector3.Distance(np.position,neighbour.position);
//if this is the first time we've seen this node
//or if we have a found a shorter path to it
if(!pq.ContainsValue(neighbour) || (scores.ContainsKey(neighbour) && estimate < scores[neighbour])) {
cameFrom[neighbour] = np;
scores[neighbour] = estimate;
try
{
pq.Add(estimate + Vector3.Distance(neighbour.position,target.position),neighbour);
} catch (System.ArgumentException e) {
//this means the key already exists i.e. there is already a distance that is this value
//this is real bad for A* that we can't have two things of the same priority but I'm just going
//to ignore it because GAME JAM
pq.Add(estimate + Vector3.Distance(neighbour.position,target.position)+Random.value/100,neighbour);
}
}
}
}
}
return null;
}
示例3: Main
static void Main()
{
SortedDictionary<byte, byte> cards = new SortedDictionary<byte, byte>();
bool hasStraightPotential = true;
byte aceCount = 0;
for (int i = 0; i < 5; i++)
{
byte number = 0;
string card = Console.ReadLine();
switch (card)
{
case "J": number = 11; break;
case "Q": number = 12; break;
case "K": number = 13; break;
case "A": number = 14; break;
default: number = byte.Parse(card); break;
}
if (!cards.ContainsKey(number))
{
cards.Add(number, 1);
}
else
{
cards[number]++;
// Once discovered key with value 2, the bool variable takes value FALSE
hasStraightPotential = false;
}
}
// We have 5 different cards -> Potential for straingth
if (hasStraightPotential)
{
if (cards.ContainsKey(14) && cards.ContainsKey(2))
{
// Potential for straight starting with A...2...
aceCount = cards[14];
cards.Add(1, 1);
cards.Remove(14);
}
// Check if elements are consecutive
for (int i = 0; i < cards.Count - 1; i++)
{
if (cards.ElementAt(i).Key != cards.ElementAt(i + 1).Key - 1)
{
hasStraightPotential = false;
break;
}
}
if (hasStraightPotential)
{
Console.WriteLine("Straight");
return;
}
else if (cards.ContainsKey(1))
{
cards.Add(14, aceCount);
cards.Remove(1);
}
}
if (cards.ContainsValue(5))
{
Console.WriteLine("Impossible"); return;
}
else if (cards.ContainsValue(4))
{
Console.WriteLine("Four of a Kind"); return;
}
else if (cards.ContainsValue(3) && cards.ContainsValue(2))
{
Console.WriteLine("Full House"); return;
}
else if (cards.ContainsValue(3) && !cards.ContainsValue(2))
{
Console.WriteLine("Three of a Kind"); return;
}
var sortedDict = (from entry in cards
orderby entry.Value descending
select entry).ToDictionary(pair => pair.Key, pair => pair.Value);
if (sortedDict.ElementAt(0).Value == 2 && sortedDict.ElementAt(1).Value == 2)
{
Console.WriteLine("Two Pairs");
}
else if (sortedDict.ElementAt(0).Value == 2 && sortedDict.ElementAt(1).Value == 1)
{
Console.WriteLine("One Pair");
}
else
{
Console.WriteLine("Nothing");
}
}
示例4: CreateLayerTheme
/// <summary>
/// Create the theme according to the individual values of the layer contents
/// </summary>
private MapObjectHolder CreateLayerTheme()
{
if (layer == null)
return null;
mapObj map = target.GetParent();
// create a new map object
mapObj newMap = new mapObj(null);
newMap.units = MS_UNITS.MS_PIXELS;
map.selectOutputFormat(map.imagetype);
// copy symbolset
for (int s = 1; s < map.symbolset.numsymbols; s++)
{
symbolObj origsym = map.symbolset.getSymbol(s);
newMap.symbolset.appendSymbol(MapUtils.CloneSymbol(origsym));
}
// copy the fontset
string key = null;
while ((key = map.fontset.fonts.nextKey(key)) != null)
newMap.fontset.fonts.set(key, map.fontset.fonts.get(key, ""));
newLayer = new layerObj(newMap);
newLayer.type = layer.type;
newLayer.status = mapscript.MS_ON;
newLayer.connectiontype = MS_CONNECTION_TYPE.MS_INLINE;
// add the classObj and styles
classObj classobj;
if (checkBoxKeepStyles.Checked)
{
classobj = layer.getClass(0).clone();
classobj.setExpression(""); // remove expression to have the class shown
// bindings are not supported with sample maps
for (int s = 0; s < classobj.numstyles; s++)
StyleBindingController.RemoveAllBindings(classobj.getStyle(s));
for (int l = 0; l < classobj.numlabels; l++)
LabelBindingController.RemoveAllBindings(classobj.getLabel(l));
newLayer.insertClass(classobj, -1);
}
else
{
classobj = new classObj(newLayer);
classobj.name = MapUtils.GetClassName(newLayer);
styleObj style = new styleObj(classobj);
style.size = 8; // set default size (#4339)
if (layer.type == MS_LAYER_TYPE.MS_LAYER_POINT)
{
// initialize with the default marker if specified in the symbol file for point symbols
symbolObj symbol;
for (int s = 0; s < map.symbolset.numsymbols; s++)
{
symbol = map.symbolset.getSymbol(s);
if (symbol.name == "default-marker")
{
style.symbol = s;
style.symbolname = "default-marker";
break;
}
}
}
MapUtils.SetDefaultColor(layer.type, style);
}
SortedDictionary<string,string> items = new SortedDictionary<string,string>();
int i = 0;
shapeObj shape;
layer.open();
layer.whichShapes(layer.getExtent());
while ((shape = layer.nextShape()) != null)
{
string value = shape.getValue(comboBoxColumns.SelectedIndex);
if (checkBoxZero.Checked && (value == "" || value == ""))
continue;
if (!items.ContainsValue(value))
{
if (i == 100)
{
if (MessageBox.Show("The number of the individual values is greater than 100 would you like to continue?","MapManager",
MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) == DialogResult.Cancel)
{
break;
}
}
items.Add(value, value);
++i;
}
}
//.........这里部分代码省略.........
示例5: PlayercastStatueGump
public PlayercastStatueGump( Mobile owner, PlayercastStatue statue )
: base(10, 10)
{
m_Owner = owner;
m_Statue = statue;
Closable = true;
Disposable = true;
Dragable = true;
int i = 0, j = 0;
int x = 20, y = 55;
#region Page 1 //Main
AddPage(1);
AddDefaultBackround(170, 245);
string[] labels0 = new string[] { "Adjust Pose", "Change Material", "Engrave", "Turn", "Change Name" };
for( i = 0, j = 0; i < labels0.Length; i++, j += 30 )
{
if( i == 2 || i == 4 )
AddButton(x, y + j, 2103, 2104, i + 1, GumpButtonType.Reply, 0);
else
AddButton(x, y + j, 2103, 2104, i + 1, GumpButtonType.Page, i < 2 ? i + 2 : i + 1);
AddLabel(x + 20, (y - 5) + j, LabelHue, (string)labels0[i]);
}
AddButton(20, 215, 3, 4, 6, GumpButtonType.Reply, 0);
AddLabel(45, 210, LabelHue, "Re-deed");
#endregion
#region Page 2 //Adjust Pose
AddPage(2);
AddDefaultBackround(170, 250);
string[] labels1 = new string[] { "All Praise Me", "Casting", "Fighting", "Hands on Hips", "Ready", "Salute" };
for( i = 0, j = 0; i < labels1.Length; i++, j += 30 )
{
AddButton(x, y + j, 2103, 2104, i + 10, GumpButtonType.Reply, 0);
AddLabel(x + 20, (y - 5) + j, LabelHue, (string)labels1[i]);
}
AddButton(125, 215, 4014, 4016, 101, GumpButtonType.Page, 1);
#endregion
#region Page 3 //Change Material
AddPage(3);
AddDefaultBackround(325, 480);
SortedDictionary<string, int> materialTable = new SortedDictionary<string, int>(StringComparer.CurrentCulture);
foreach( int v in Enum.GetValues(typeof(MaterialType)) )
{
if( !materialTable.ContainsValue(v) && v != 0 )
materialTable.Add(Enum.GetName(typeof(MaterialType), v), v);
}
i = j = 0;
int k = 0;
foreach( KeyValuePair<string, int> kvp in materialTable )
{
if( i <= (materialTable.Count / 2) )
{
AddButton(x, y + j, 2103, 2104, kvp.Value, GumpButtonType.Reply, 0);
AddLabel(x + 20, (y - 5) + j, LabelHue, Util.SplitString(kvp.Key));
j += 30;
}
else
{
AddButton(x + 145, y + k, 2103, 2104, kvp.Value, GumpButtonType.Reply, 0);
AddLabel(x + 145 + 20, (y - 5) + k, LabelHue, Util.SplitString(kvp.Key));
k += 30;
}
i++;
}
AddButton(280, 445, 4014, 4016, 101, GumpButtonType.Page, 1);
#endregion
#region Page 4 //Turn
AddPage(4);
AddDefaultBackround(185, 280);
AddButton(65, 55, 4500, 4500, 450, GumpButtonType.Reply, 0);
AddButton(100, 80, 4501, 4501, 451, GumpButtonType.Reply, 0);
AddButton(120, 115, 4502, 4502, 452, GumpButtonType.Reply, 0);
AddButton(100, 150, 4503, 4503, 453, GumpButtonType.Reply, 0);
AddButton(65, 165, 4504, 4504, 454, GumpButtonType.Reply, 0);
AddButton(30, 150, 4505, 4505, 455, GumpButtonType.Reply, 0);
AddButton(15, 115, 4506, 4506, 456, GumpButtonType.Reply, 0);
AddButton(30, 80, 4507, 4507, 457, GumpButtonType.Reply, 0);
AddButton(140, 245, 4014, 4016, 101, GumpButtonType.Page, 1);
//.........这里部分代码省略.........