//统计数组中出现次数超过一半的数字 #include <stdio.h> int Find(int *arr, int len) { int num = 0; //当前数字 int times = 0; //当前数字出现的次数 int i = 0; for (i = 0; i<len; i++) { if (times == 0) { num = arr[i]; times = 1; } else if (arr[i] == num) times++; else times--; }
为了排版方便或者是输出文件命名整洁,通常需要给数字前面补0来做统一.Python中有一个zfill函数用来给字符串前面补0,非常有用,这个zfill看起来也就是zero fill的缩写吧,看一下如何使用: n = " s = n.zill(5) ' zfill也可以给负数补0: n = '-123' s = n.zfill(5) assert s == '-0123' 对于纯数字也可以通过格式化的方式来补0: n = 123 s = '%05d' % n ' 参考: http://www.sha
python中的axis究竟是如何定义的呢?他们究竟代表是DataFrame的行还是列? 直接上代码people=DataFrame(np.random.randn(5,5), columns=['a','b','c','d','e'], index=['Joe','Steve','Wes','Jim','Travis']) a b c d eJoe 0.814300 -0.495764 0.3
转自(http://blog.csdn.net/aimingoo/article/details/4492592) 通常遇到的一个问题是日期的“1976-02-03 HH:mm:ss”这种格式 ,我的比较简单的处理方法是这样: function formatDate(d) { var D=['00','01','02','03','04','05','06','07','08','09'] with (d || new Date) return [ [getFullYear(), D[getMo
python中的axis究竟是如何定义的呢?他们究竟代表是DataFrame的行还是列? 直接上代码people=DataFrame(np.random.randn(5,5), columns=['a','b','c','d','e'], index=['Joe','Steve','Wes','Jim','Travis']) a b c d eJoe 0.814300 -0.495764 0.