锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
sprintf( result, "%d", num );
]]>
]]>
#ifndef AUTOPTR
#define AUTOPTR

/**//**
* 鏅鴻兘鎸囬拡綾?br>
*/
template<class T>
class AutoPtr
{
public :
AutoPtr(T* p = 0) : pointee(p)
{} //榛樿鏋勯犲嚱鏁?/span>
template<class U>
AutoPtr(AutoPtr<U>& rhs) : pointee(rhs.release())
{}//澶嶅埗鏋勯犲嚱鏁?/span>

~AutoPtr()
{delete pointee;}
template<class U>
AutoPtr<T>& operator=(AutoPtr<U>& rhs)
{ //璧嬪煎嚱鏁?/span>
if (this != &rhs)
{
reset(rhs.release());
}
return *this;
}

T& operator*() const
{return *pointee;}

T* operator->() const
{return pointee;}

T* get() const
{return pointee;} //鑾峰彇dumb pointer

T* release()
{ //閲婃斁dumb pointer 鐨勬嫢鏈夋潈錛屽茍榪斿洖鍏跺?/span>
T* oldPointee == pointee;
pointee = 0;
return oldPointee;
}

void reset(T* p=0)
{ //閲嶅緗畃鎸囬拡
if (pointee != p)
{
delete pointee;
pointee = p;
}
}
private :
T* pointee;
};
#endif AUTOPTR
test.cpp
#include "AutoPtr.h"
#include <iostream>
#include <string>
using namespace std;

int main()
{
AutoPtr<int> p = new int;
*p = 100;
printf("%d\n", *p);
AutoPtr<string> sp = new string;
*sp = "hello world";
printf("%s\n", sp->c_str());
return 0;
}
]]>
]]>
鍋囪涓涓?BR>struct TreeNode
{
int tData;
TreeNode *lp, *rp;//宸﹀彸鍎垮瓙鐨勬寚閽?BR>};
瑙勫畾鐢ㄩ掑綊鍓嶅簭閬嶅巻浠Node涓烘牴浜屽弶鏍?鎶婅妭鐐規寚閽堜繚瀛樺湪rs鏁扮粍涓?騫惰繑鍥炶妭鐐逛釜鏁癱nt.
鍥犱負瑕佺敤閫掑綊閬嶅巻, 鎵浠nt蹇呴』淇濈暀閫掑綊姣忓眰cnt鐨勫?
瀹炵幇鏂規硶鏈変袱縐?
1:鐢╞y value浼犲?cnt鍒濆間負0;
int travel(TreeNode *pNode, TreeNode **rs, int &cnt)
{
if (pNode == NULL)
{
return cnt;
}
rs[cnt++] = pNode;
travel(pNode->lp, rs, cnt);
travel(pNode->rp, rs, cnt);
return cnt;
}
2:鐢ㄩ潤鎬佸彉閲忓疄鐜?BR>int travel(TreeNode *pNode, TreeNode **rs)
{
static int cnt = 0;
if (pNode == NULL)
{
return cnt;
}
rs[cnt++] = pNode;
travel(pNode->lp, rs, cnt);
travel(pNode->rp, rs, cnt);
return cnt;
}
瀵規瘮1鍜?,鏄劇劧2鐨勫嚱鏁拌姣?鐨勬潵寰楀弸濂?鍥犱負鍦?涓鍔犵殑鍙傛暟cnt涓嶅睘浜庡嚱鏁版帴鍙?鍙槸涓轟簡鍑芥暟鐨勫疄鐜拌屽紩鍏ョ殑,鎵浠ュ弬鏁癱nt鐨勫嚭鐜?鐮村潖浜嗘帴鍙g殑鍙嬪ソ鎬?浣嗘槸濡傛灉鐢?鐨勬柟娉?鍦ㄥ嚱鏁板啀嬈′嬌鐢ㄧ殑鏃跺檚tatic int cnt鐨勫間粛淇濇寔涓婃鍑芥暟琚皟鐢ㄦ椂鐨勫?鑰屾病鏈夊垵濮嬪寲涓?,浠庤岃揪涓嶅埌鍑芥暟鍐嶆琚皟鐢ㄧ殑鐩殑.閭f湁娌℃湁濂界殑瑙e喅鏂規硶鍛?
鎴戜滑鍒╃敤鍑芥暟閲嶈澆,閲嶈澆travel鍑芥暟,騫跺湪姝ゅ嚱鏁板唴璋冪敤1鐨則ravel鍑芥暟.
int travel(TreeNode *pNode, TreeNode **rs)
{
int cnt = 0;
return travel(TreeNode *pNode, TreeNode **rs, int &cnt);
}
榪欐牱鐨勮瘽,灝辮兘寰堝ソ鐨勮В鍐充簡鍑芥暟鎺ュ彛鐨勫弸濂芥?鑰屽張涓嶄細鍑虹幇static鍙橀噺鐨勫壇浣滅敤浜?
浠ヤ笂鏄皬寮熺殑涓鐐規剼瑙?
Description Input Output
Michael鍠滄婊戦洩鐧捐繖騫朵笉濂囨紝 鍥犱負婊戦洩鐨勭‘寰堝埡嬋銆傚彲鏄負浜嗚幏寰楅熷害錛屾粦鐨勫尯鍩熷繀欏誨悜涓嬪炬枩錛岃屼笖褰撲綘婊戝埌鍧″簳錛屼綘涓嶅緱涓嶅啀嬈¤蛋涓婂潯鎴栬呯瓑寰呭崌闄嶆満鏉ヨ澆浣犮侻ichael鎯崇煡閬撹澆涓涓尯鍩熶腑鏈闀垮簳婊戝潯銆傚尯鍩熺敱涓涓簩緇存暟緇勭粰鍑恒傛暟緇勭殑姣忎釜鏁板瓧浠h〃鐐圭殑楂樺害銆備笅闈㈡槸涓涓緥瀛? 1 2 3 4 5
16 17 18 19 6
15 24 25 20 7
14 23 22 21 8
13 12 11 10 9
涓涓漢鍙互浠庢煇涓偣婊戝悜涓婁笅宸﹀彸鐩擱偦鍥涗釜鐐逛箣涓錛屽綋涓斾粎褰撻珮搴﹀噺灝忋傚湪涓婇潰鐨勪緥瀛愪腑錛屼竴鏉″彲婊戣鐨勬粦鍧′負24-17-16-1銆傚綋鐒?5-24-23-...-3-2-1鏇撮暱銆備簨瀹炰笂錛岃繖鏄渶闀跨殑涓鏉°?/FONT>
杈撳叆鐨勭涓琛岃〃紺哄尯鍩熺殑琛屾暟R鍜屽垪鏁癈(1 <= R,C <= 100)銆備笅闈㈡槸R琛岋紝姣忚鏈塁涓暣鏁幫紝浠h〃楂樺害h錛?<=h<=10000銆?/FONT>
杈撳嚭鏈闀垮尯鍩熺殑闀垮害銆?BR>
鎴戞彁浜ょ殑紼嬪簭錛?BR>
using namespace std;
const int MAX = 102;
struct pos
{
int i,j,p;//i->琛?j->鍒楋紱p->鏉ユ簮鏂瑰悜
};
int path(int [MAX][MAX],int [MAX][MAX],int[][MAX],int,int);
int main()
{
int input[MAX][MAX];
int result[MAX][MAX];
int status[MAX][MAX];
int m,n;
int i,j;
int max,ans;
cin>>m>>n;
for (i = 0; i<=m+1; i++)
for (j = 0; j<=n+1; j++)
{
input[i][j] = 10001;
result[i][j] = 0;
status[i][j] = 0;
}
for (i = 1; i<=m; i++)
for (j = 1; j<=n; j++)
{
cin>>input[i][j];
}
for (i = 1; i<=m; i++)
for (j = 1; j<=n; j++)
path(input,result,status,i,j);
max = 0;
for (i = 1; i<=m; i++)
for (j = 1; j<=n; j++)
if (max<result[i][j])
max = result[i][j];
cout<<max<<endl;
return 0;
}
int path(int input[MAX][MAX],int result[MAX][MAX],int status[MAX][MAX],int i,int j)
{
pos pack[MAX*MAX];
int max,g,h;
int ii;
int top = 0;
int p = 0;
int incr[4][2] = {{-1,0},{0,1},{1,0},{0,-1}};//澧為噺琛?BR>
//鍒濆鍖?/SPAN>
if (result[i][j]>0)
{
return 0;
}
else
{
pack[top].i = i;
pack[top].j = j;
pack[top].p = p;
status[i][j] = -1;
}
while (top>=0||p<4)
{
if (p<4)
{
g = pack[top].i+incr[p][0];
h = pack[top].j+incr[p][1];
//鍒ゆ柇鏄惁鍚堟硶
if (input[pack[top].i][pack[top].j]>input[g][h])
{
if (result[g][h]>0||status[g][h]==-1)//
p++;
else
{
//榪涙爤
top++;
pack[top].i = g;
pack[top].j = h;
pack[top].p = p;
status[g][h] = -1;
p = 0;
}
}//鍚堟硶
else
{
p++;
}
}
else//p==4鏃?/SPAN>
{
max = 0;
for (ii = 0; ii<4; ii++)//鍥涗釜鏂瑰悜
{
g = pack[top].i+incr[ii][0];
h = pack[top].j+incr[ii][1];
if (input[pack[top].i][pack[top].j]>input[g][h]&&max<result[g][h])
max = result[g][h];
}
result[pack[top].i][pack[top].j] = max+1;
top--;//鍥炴函
p = pack[top].p+1;
}
}
return 0;
}
鍏堣阿鍟?鍛靛懙.
#include<iostream>
using namespace std;
struct date

{
unsigned int year,month,day;
};
unsigned int sum(unsigned int,unsigned int,unsigned int);
bool is_eyear(unsigned int);
void main()

{
date temp;
unsigned int total;
cout<<"please input date,formation:2005 12 05"<<endl;
cin>>temp.year>>temp.month>>temp.day;
total=sum(temp.year,temp.month,temp.day);
cout<<"total day="<<total<<endl;
}
unsigned int sum(unsigned int y,unsigned int m,unsigned int d)

{
unsigned int t=0;
if(m<1)
{
t=0;
return t;
}else if(m==1)
{
t=d;
return t;
}else
{
switch(m)
{
case 3:
if(is_eyear(y))
t=d+sum(y,m-1,29);
else t=d+sum(y,m-1,28);
break;
case 2:case 4:case 6:case 8:case 9:case 11:
t=d+sum(y,m-1,31);
break;
default :
t=d+sum(y,m-1,30);
break;
}
}
return t;
}//璁$畻鏃ユ湡鎬繪暟鍑芥暟

/**//***************

bool is_eyear(unsigned int y)
{
if(y%400==0) return 1;
else if(y%4==0) return 1;
else return 0;
}//鍒ゆ柇闂板勾鍑芥暟
**************/



bool is_eyear(unsigned int y)

{
if(y%100==0&&y%400==0) return 1;
if(y%100!=0&&y%4==0) return 1;
return 0;
}//鍒ゆ柇闂板勾鍑芥暟

#include<iostream>
#include<string>
using namespace std;
void main()

{
char *a="010000010111101101000000000";
int i,temp0=0,temp1=0,max0=0,max1=0;//瀵瑰彉閲忓垵濮嬪寲錛屽鏋滀笉鍒濆鍖栵紝鍙橀噺鍊兼槸闅忔満鐨?/SPAN>
for(i=0;i<strlen(a);i++)
{
switch(a[i])
{
case '0':
{
temp0++;
if(a[i+1]=='1'||i==strlen(a)-1)
{
if(max0<temp0) max0=temp0;
temp0=0;
}
break;
}
case '1':
{
temp1++;
if(a[i+1]=='0'||i==strlen(a)-1)
{
if(max1<temp1) max1=temp1;
temp1=0;
}
break;
}
}
}
cout<<"max0="<<max0<<endl;
cout<<"max1="<<max1<<endl;
}