用C#编程:输入一些给定的字符串,统计它们各自出现的次数怎么写啊
补充:求表达式1-2+3-4+...+m的值用C#怎么写,谢谢!
追问:可以写好一点吗 ?我不是很清楚啊!呵呵
补充:求表达式1-2+3-4+...+m的值用C#怎么写,谢谢!
追问:可以写好一点吗 ?我不是很清楚啊!呵呵
答案:正则表达式可以实现.想了解详细 可以在百度里搜索 C# 正则表达式.
indexof这个方法可以实现using System;using System.Collections.Generic;using System.Linq;using System.Text;
namespace ConsoleApplication1{ class Program { static void Main(string[] args) { List<String> record = new List<String>() { "Hello","World","This","is","my","first","try","to","say","Hello" };
var query = from r in record group r by r.ToLower() into g select new { Count = g.Count(), Value = g.Key };
foreach (var v in query) { Console.WriteLine("Value = {0}, Count = {1}", v.Value, v.Count); } } }}=================================================使用LINQ TO OBJECT,一句话就搞定了附上程序#include <iostream>#include <cstdlib>using namespace std;int main(void)unsigned NumDigit(unsigned n);//我相信这个整数不会超过255位吧 unsigned res = 0; itoa(n, c, 10); for (int i = 0; c[i] != NULL; ++i) res++; return res;}
用C#编程:输入一些给定的字符串,统计它们各自出现的次数怎么写啊这里有视频教程可以看下 http://www.alisoho.comusing System;
using System.Collections.Generic;
using System.Text;namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int i = 1;
int sum = 0;
int m = Convert.ToInt32(Console.ReadLine());
while (i <= m)
{
if (i % 2 == 0)
{
sum -= i;
}
else
{
sum += i;
}
i++;
}
Console.WriteLine("{0}", sum);
Console.Read();
}
}
}CONVERT强制转换成整型int num=0;
for(int i=1;i<m+1;i++)
{
if(i%2==0)
num-=i;
else
num+=i;
}
Console.WriteLine(num);好久没有碰问问了。声望值降的都快没有了。所以楼主定要采纳我为满意哦。谢谢哈。
附上答案吧。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string Str = "AaccdDDeFFeetttee";
string CapStr = Str.ToUpper();
List<string> CharTemp = new List<string>();
for (int i = 0; i < CapStr.Length; i++)
{
if (CharTemp.Count == 0)
{
CharTemp.Add(CapStr[i].ToString());
continue;
}
int count = 0;
for (int j = 0; j < CharTemp.Count; j++)
{
if (!CapStr[i].ToString().Equals(CharTemp[j].ToString()))
{
count++;
}}
if (count == CharTemp.Count)
{
CharTemp.Add(CapStr[i].ToString());
&
上一个:c# button控件编程问题
下一个:C#语言编程问题