本文整理汇总了C#中ST.put方法的典型用法代码示例。如果您正苦于以下问题:C# ST.put方法的具体用法?C# ST.put怎么用?C# ST.put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ST
的用法示例。
在下文中一共展示了ST.put方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
public static void Main(string[] args)
{
ST<string, int?> st = new ST<string, int?>();
// Adaug in colectie 3 perechi (cheie, valoare)
st.put("Marin", 34);
st.put("Ionel", 22);
st.put("Cornel", 45);
// Afisez elementele colectiei
foreach (var item in st.keys())
{
Console.WriteLine(item);
}
// Determin numarul de elemente din colectie
Console.WriteLine("Dimensiunea tabelei simbolice este {0}", st.size());
string nume = "Marin";
if (st.contains(nume))
{
Console.WriteLine("{0} are {1} ani", nume, st.get(nume));
}
else
{
Console.WriteLine("{0} nu se afla in colectie", nume);
}
st.put(nume, 35);
Console.WriteLine("{0} are {1} ani", nume, st.get(nume));
// Elimin din colectie o pereche (cheie, valoare)
st.put(nume, null);
foreach (var item in st.keys())
{
Console.WriteLine(item);
}
}
示例2: Main
/// <summary>
/// Citeste un parametru din linia de comanda si o lista de cuvinte
/// din fisier si afiseaza cuvantul care apare cel mai
/// frecvent (al carui lungime depaseste valoarea data in linia de
/// comanda. De asemenea afiseaza numarul de cuvinte ale caror lungime
/// depaseste valoarea din linia de comanda si numarul de astfel de cuvinte
/// distincate
/// </summary>
/// <param name="args"></param>
static void Main(string[] args)
{
int distinct = 0, words = 0;
int minlen = int.Parse(args[0]);
ST<String, int?> st = new ST<String, int?>();
// Calculeaza frecventa de aparitie a fiecarui cuvant
string[] keys = Util.readWords("tale.txt");
foreach (var key in keys)
{
if (key.Length < minlen)
continue;
words++;
if (st.contains(key)) {
st.put(key, st.get(key) + 1);
}
else {
st.put(key, 1);
distinct++;
}
}
// gaseste cheia care apare cel mai frecvent
String max = "";
st.put(max, 0);
foreach (string word in st.keys())
{
if (st.get(word) > st.get(max))
max = word;
}
Console.WriteLine("{0} {1}", max, st.get(max));
Console.WriteLine("Cuvinte distincte: {0}", distinct);
Console.WriteLine("Cuvinte: {0}", words);
}