hello world

来源:互联网 发布:用户角色模型 java 编辑:程序博客网 时间:2024/06/02 21:07

hello world.

demo code.

// 60_FineNumberAppearOnceTheOthersAppear3Times.cpp : Defines the entry point for the console application.///*version: 1.0author: hellogiserblog: http://www.cnblogs.com/hellogiserdate: 2014/5/28*/#include "stdafx.h"/*1,1,1,2,2,2,3001,001,001,010,010,010011number of 1: 003+030+011 = 044 044 % 3 = 011 ===>3*/int FindNumberAppearOnce_WithTheOther3Times(int data[],int length){if(NULL==data||length<=0)return -1;const int N = 32;// count the 1s of 32 bitint counts[N] = {0};for (int i=0;i<length;++i){for (int j=0;j<N;++j){counts[j] = (counts[j] + (data[i]>>j&1))%3;}}// get the resultint result=0;for (int j=0;j<N;++j)result +=(counts[j]<<j);return result;}void test_base(int data[],int length){int result = FindNumberAppearOnce_WithTheOther3Times(data,length);printf("%d \n",result);}void test_case1(){int data[] = {1,1,1,2,2,2,3};int length = sizeof(data)/sizeof(int);test_base(data,length);}void test_case2(){int data[] = {1,1,1,2,2,2,3,3,3,4};int length = sizeof(data)/sizeof(int);test_base(data,length);}void test_main(){test_case1();test_case2();}int _tmain(int argc, _TCHAR* argv[]){test_main();return 0;}/*34*/


0 0
原创粉丝点击