文章分类 - Algorithm
摘要:已知2个整形数据a,b.不使用if,?:以及其他任何条件判断的语法,找出a跟b中数据的大者。int max(int a,int b){ return (a+b+abs(a-b))/2;}abs() 求绝对值
阅读全文
posted @ 2012-04-01 17:09
xfyn
摘要:int [] array = new int [*] ;int temp = 0 ;for (int i = 0 ; i < array.Length - 1 ; i++){for (int j = i + 1 ; j < array.Length ; j++){if (array[j] < array[i]){temp = array[i] ;array[i] = array[j] ;array[j] = temp ;}}}
阅读全文
posted @ 2011-02-22 21:35
xfyn
摘要:public class MainClass { public static void Main() { Console.WriteLine(Foo(30)); } public static int Foo(int i) { if (i <= 0) return 0; else if(i > 0 && i <= 2) return 1; else return Foo(i -1) + Foo(i - 2); } }
阅读全文
posted @ 2011-02-22 21:09
xfyn