Console.WriteLine("请输入截止数字?退出请输入y");
string input = Console.ReadLine();
int n = Convert.ToInt32(input);
int count = ; //计数
for (int i = ; i <= n; i++)
{
string str = i.ToString();//要匹配的字符串
string pattern=""; //要匹配的正则表达式模式
MatchCollection matches = Regex.Matches(str, pattern); //正则表达式匹配验证
count += matches.Count; //获得匹配数量,加到计数上,
//foreach (Match NextMatch in matches) //遍历获得数量也行,不过效率低
//{
// count++;
//}
}
Console.WriteLine("在0-{0}中1出现了"+count+"次",input);
相关文章
- C语言 编写程序数一下1到100的所有整数中出现多少次数字9。
- C语言 编写程序数一下1到100的所有整数中出现多少次数字9
- C语言:编写程序数一下 1到 100 的所有整数中出现多少次数字9
- 《剑指offer》整数中1出现的次数
- CCF计算机软件能力认证试题练习201312-1-出现次数最多的数
- 1.找出字符串中出现的次数;2.利用循环去除空格。3.字符串以什么结尾
- 《剑指offer》— JavaScript(31)整数中1出现的次数(从1到n整数中1出现的次数)
- 剑指Offer 31. 整数中1出现的次数(从1到n整数中1出现的次数) (其他)
- 题目1373:整数中1出现的次数(从1到n整数中1出现的次数) 数位DP
- 找出一个数组中出现次数超过一半的那个数字,要求时间复杂度O(n)和空间复杂度为O(1)。