最近有在啃《C#入门经典》这本书,这篇日志以后将不定期更新,专门记录这本书中有意思的小算法好了~~
1.除法小技巧(Page:46):
var1=(var2!=0)&&(var3/var2>2);
We read the world wrong and say that it deceives us.
最近有在啃《C#入门经典》这本书,这篇日志以后将不定期更新,专门记录这本书中有意思的小算法好了~~
1.除法小技巧(Page:46):
var1=(var2!=0)&&(var3/var2>2);
在三角猫 DeltaCat的部落格看到一篇关于循环分组示例的文章,特转载于此:
今天,有个网友咨询一个正则表达式的使用,问题描述如下:
“@Beijing|北京|101@Shanghai|上海|102@Tianjin|天 津|103@Chongqing|重庆|104@Haerbin|哈尔滨|105@Dalian|大连|106”
分解成 “Beijing 北京 101“,”Shanghai 上海 102” 的单独项。
这个正则的使用,是循环分组的一个典型应用。
C#的写法:
foreach (Match m in reg.Matches(str))
{
Console.WriteLine(“{0} {1} {2}”, m.Groups[1].Value, m.Groups[2].Value, m.Groups[3].Value);
}
刚才在CSDN看到了一个蛮有意思的算法题目:
有两个变量a和b,不用if、?:、switch或其他判断语句,找出两个数中比较大的那个?
大家给出了各种各样的答案,其中有几个我觉得很赞,
1)
int max=((a+b)+abs(a-b))/2 (这是给出的参考答案)
2)
int max(int a,int b)
{
int arr[]={a,b};
return arr[a
(我觉得这个确实很巧妙,确实)
突然意识到第二个使用了小于号。。。虽然想法不错 但是 违反规则了 Pass
这个实现了1-9的循环显示输出,挺巧的一个方法。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace P2._2
{
class Program
{
static void Main(string[] args)
{
int x = 0;
while (true)
{
x = (x + 1) % 10;
Console.WriteLine(“the Value of x is {0}”,x);
}
Console.ReadLine();
}
}
}