锘??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲国产成人av好男人在线观看,欧美日韩国产美女,欧美伊人影院http://www.shnenglu.com/hunter/archive/2010/05/29/116663.htmlhunterhunterFri, 28 May 2010 23:37:00 GMThttp://www.shnenglu.com/hunter/archive/2010/05/29/116663.htmlhttp://www.shnenglu.com/hunter/comments/116663.htmlhttp://www.shnenglu.com/hunter/archive/2010/05/29/116663.html#Feedback0http://www.shnenglu.com/hunter/comments/commentRss/116663.htmlhttp://www.shnenglu.com/hunter/services/trackbacks/116663.html鍒涘緩涓涓簩鍙夋爲錛屼笅闈?wbr>鏄嚑涓父鐢ㄥ嚱鏁扮殑浣跨敤鏂規硶鍜屼唬琛ㄧ殑鎰忔?br>#include
#include
#include
#include
using namespace std;

錛?錛夊垱寤轟竴涓暟緇勶紝騫舵坊鍔犳暟鎹?br>    vector v_Arry;
    v_Arry.push_back(5);
    v_Arry.push_back(6);
    v_Arry.push_back(4);
    v_Arry.push_back(8);
    v_Arry.push_back(2);
    v_Arry.push_back(3);
    v_Arry.push_back(7);
    v_Arry.push_back(1);
    v_Arry.push_back(9);
    v_Arry.push_back(10);
    v_Arry.push_back(55);

錛?錛塵ake_heap錛坴_Arry.begin錛堬級, v_Arry.end錛堬級, less()) //寤哄爢錛堝叾瀹炲氨鏄緩浜屽弶鏍戯級,鏍硅妭鐐規槸鏈澶у鹼紝鍏舵瘡涓涓妭鐐歸兘灝忎簬鎴栫瓑浜庡叾鐖惰妭鐐癸紱浣跨敤greater()鍒欑浉鍙嶏紝鏍硅妭鐐規槸鏈灝忓鹼紝鍏舵瘡涓涓妭鐐?wbr>閮藉ぇ浜庢垨絳変簬鍏剁埗鑺傜偣

錛?錛夋鏃跺彲浠ヨ緭鍑烘煡鐪嬩竴涓嬪緩濂界殑鍫嗘槸涓嶆槸涓涓爣鍑嗙殑浜屽弶鏍?br>鎴戠殑杈撳嚭緇撴灉鏄細55錛?0錛?錛?錛?錛?wbr>3錛?錛?錛?錛?錛?wbr>2
鍙樻垚浜屽弶鏍戝氨鏄涓嬶細
<!--[if !vml]--><!--[endif]--> <!--[if !vml]--><!--[endif]-->

 

緇撴灉涓嶆槸鍞竴鍗曚竴瀹氳婊¤凍鐖惰妭鐐瑰拰瀛愯妭鐐圭殑澶у皬鍏崇郴銆?br>錛?錛塸op_heap(v_Arry.begin(), v_Arry.end());//鎶婃牴鑺傜偣縐誨埌鏈熬錛屽茍娌℃湁鍒犻櫎
     v_Arry.pop_back();//鍒犻櫎璇ヨ妭鐐?br>    姝ゆ椂杈撳嚭緇撴灉錛?0錛?wbr>9錛?錛?錛?錛?錛?wbr>4錛?錛?錛?
浜屽弶鏍戝涓嬶細

 

錛?錛塿_Arry.push_back(55); //鍙槸娣誨姞鏁版嵁鏀懼埌瀛愯妭鐐?br>    push_heap(v_Arry.begin(), v_Arry.end());//寰浜屽弶鏍?wbr>涓彃鍏ユ暟鎹紝婊¤凍瀛愯妭鐐瑰皬浜庣瓑浜庣埗鑺傜偣
姝ゆ椂杈撳嚭緇撴灉錛?5錛?wbr>10錛?錛?錛?錛?錛?錛?錛?錛?錛?
浜屽弶鏍戝涓嬶細

 

錛?錛塻ort_heap(v_Arry.begin(), v_Arry.end());//瀵逛簩鍙夋爲鎵鏈夎妭鐐硅繘琛屾帓搴?br>姝ゆ椂杈撳嚭緇撴灉錛?錛?錛?錛?錛?錛?錛?錛?錛?錛?0錛?5

錛?錛塮ind ( v_Arry.begin(), v_Arry.end()錛?value );// 浠巄egin鍒癳nd鏌ユ壘value錛岃嫢鎵?wbr>涓嶅埌錛岃繑鍥瀍nd

鍘熸枃鍦板潃錛?a >http://blog.zol.com.cn/1356/article_1355249.html


hunter 2010-05-29 07:37 鍙戣〃璇勮
]]>
榪愮敤璁℃暟鎺掑簭榪涜鍩烘暟鎺掑簭http://www.shnenglu.com/hunter/archive/2010/03/11/109411.htmlhunterhunterThu, 11 Mar 2010 03:08:00 GMThttp://www.shnenglu.com/hunter/archive/2010/03/11/109411.htmlhttp://www.shnenglu.com/hunter/comments/109411.htmlhttp://www.shnenglu.com/hunter/archive/2010/03/11/109411.html#Feedback0http://www.shnenglu.com/hunter/comments/commentRss/109411.htmlhttp://www.shnenglu.com/hunter/services/trackbacks/109411.html閲嶅瀵規墍鏈夌殑d浣嶆暟瀛楅兘榪涜鎺掑簭錛屼粎闇瑕乨閬嶅氨鍙互灝嗕竴鍫嗗崱鐗囪繘琛屾帓搴忋?br>榪欓噷鍙堣繍鐢ㄤ簡鍩烘暟鎺掑簭鐨勬柟娉曪紝鎵浠ユ葷殑鏃墮棿澶嶆潅搴︿負O(n*d)銆?br>
#include <stdio.h>
#include 
<stdlib.h>
#include 
<iostream>
#include 
<cmath>
using namespace std;

void CountSort(int a[], int b[],int num,int d)   //璁℃暟鎺掑簭
{
    
int* c = new int[10];
    
int index;
    
for (int i=0;i<=9;i++)
       c[i]
=0;
    
int size = num;
    
for (int j=0;j<size;j++)
    
{
        index
=a[j]%(int)pow(10.0,d)/(int)pow(10.0,d-1);
        c[index]
++;
    }

    
//c[i]鍖呭惈絳変簬i鐨勫厓绱犱釜鏁?/span>
    for (i=1;i<=9;i++)
       c[i]
=c[i]+c[i-1];
    
//c[i]鍖呭惈灝忎簬絳変簬i鐨勫厓绱犱釜鏁?/span>
    for (j=size-1;j>=0;j--)
    
{
        index
=a[j]%(int)pow(10.0,d)/(int)pow(10.0,d-1);
        b[c[index]
-1]=a[j];
        c[index]
--;
    }


    
for (j=0;j<size;j++)    //鏇存柊涓嬈℃帓搴忓悗鐨刟鏁扮粍
    {
        a[j]
=b[j];
    }

        delete [] c;
}


void RadixSort(int a[],int b[],int d,int num)   //鍩烘暟鎺掑簭
{
    
for(int i=1;i<=d;i++)
        CountSort(a,b,num,i);
}



void main()
{
    
int num,d;
    cout
<<"杈撳叆涓暟鍙婁綅鏁?/span>"<<endl;
    cin
>>num>>d;
    
int* a = new int[num];
    
int* b = new int[num];
    cout
<<"鎺掑簭鍓嶏細"<<endl;
    
for(int i=0;i<num;i++)
    
{
        cin
>>a[i];
    }

        
    RadixSort(a,b,d,num);

    cout
<<"鎺掑簭鍚庯細"<<endl;
    
for (int j=0;j<num;j++)
    
{
        cout
<<b[j]<<endl;
    }


    delete [] a;
    delete [] b;
}



hunter 2010-03-11 11:08 鍙戣〃璇勮
]]>
sizeof鐢ㄦ硶錛堣漿錛?/title><link>http://www.shnenglu.com/hunter/archive/2010/03/10/109400.html</link><dc:creator>hunter</dc:creator><author>hunter</author><pubDate>Wed, 10 Mar 2010 15:36:00 GMT</pubDate><guid>http://www.shnenglu.com/hunter/archive/2010/03/10/109400.html</guid><wfw:comment>http://www.shnenglu.com/hunter/comments/109400.html</wfw:comment><comments>http://www.shnenglu.com/hunter/archive/2010/03/10/109400.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/hunter/comments/commentRss/109400.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/hunter/services/trackbacks/109400.html</trackback:ping><description><![CDATA[<span style="WIDOWS: 2; TEXT-TRANSFORM: none; TEXT-INDENT: 0px; BORDER-COLLAPSE: separate; FONT: medium Simsun; WHITE-SPACE: normal; ORPHANS: 2; LETTER-SPACING: normal; COLOR: rgb(0,0,0); WORD-SPACING: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" class=Apple-style-span><span style="TEXT-ALIGN: left; LINE-HEIGHT: 21px; FONT-FAMILY: simsun, 瀹嬩綋, sans-serif; COLOR: rgb(70,70,70); FONT-SIZE: 14px" class=Apple-style-span> <p style="PADDING-BOTTOM: 0px; LINE-HEIGHT: 21px; BORDER-RIGHT-WIDTH: 0px; LIST-STYLE-TYPE: none; MARGIN: 0px 0px 5px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; WORD-WRAP: normal; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; WORD-BREAK: normal; BORDER-LEFT-WIDTH: 0px; PADDING-TOP: 0px" dir=ltr>C璇█涓垽鏂暟鎹被鍨嬮暱搴︾<br>鐢ㄦ硶<br> <wbr> <wbr><span id="hvzpftn" class=Apple-converted-space> </span> <wbr> <wbr><span id="hvzpftn" class=Apple-converted-space> </span>sizeof(綾誨瀷璇存槑絎︼紝鏁扮粍鍚嶆垨琛ㄨ揪寮?;<br>鎴?br> <wbr> <wbr><span id="hvzpftn" class=Apple-converted-space> </span> <wbr> <wbr><span id="hvzpftn" class=Apple-converted-space> </span>sizeof 鍙橀噺鍚?br><br>1. 瀹氫箟錛?br>sizeof鏄疌/C++涓殑涓涓搷浣滅錛坥perator錛夋槸涔燂紝綆鍗曠殑璇村叾浣滅敤灝辨槸榪斿洖涓涓璞℃垨鑰呯被鍨嬫墍鍗犵殑鍐呭瓨瀛楄妭鏁般?br>MSDN涓婄殑瑙i噴涓猴細<br>The sizeof keyword gives the amount of storage, in bytes, associated with a variable or a type (including aggregate types). This keyword returns a value of type size_t.<br>鍏惰繑鍥炲肩被鍨嬩負size_t錛屽湪澶存枃浠秙tddef.h涓畾涔夈傝繖鏄竴涓緷璧栦簬緙栬瘧緋葷粺鐨勫鹼紝涓鑸畾涔変負<br>typedef unsigned int size_t;<br>涓栦笂緙栬瘧鍣ㄦ灄鏋楁繪伙紝浣嗕綔涓轟竴涓鑼冿紝瀹冧滑閮戒細淇濊瘉char銆乻igned char鍜寀nsigned<br>char鐨剆izeof鍊間負1錛屾瘯绔焎har鏄垜浠紪紼嬭兘鐢ㄧ殑鏈灝忔暟鎹被鍨嬨?br>2. 璇硶錛?br>sizeof鏈変笁縐嶈娉曞艦寮忥紝濡備笅錛?br>1) sizeof( object ); // sizeof( 瀵硅薄 );<br>2) sizeof( type_name ); // sizeof( 綾誨瀷 );<br>3) sizeof object; // sizeof 瀵硅薄;<br>鎵浠ワ紝<br>int i;<br>sizeof( i ); <wbr><span id="hvzpftn" class=Apple-converted-space> </span>// ok<br>sizeof i; <wbr> <wbr> <wbr> <wbr><span id="hvzpftn" class=Apple-converted-space> </span>// ok<br>sizeof( int ); // ok<br>sizeof int; <wbr> <wbr> <wbr><span id="hvzpftn" class=Apple-converted-space> </span>// error<br>鏃㈢劧鍐欐硶3鍙互鐢ㄥ啓娉?浠f浛錛屼負姹傚艦寮忕粺涓浠ュ強鍑忓皯鎴戜滑澶ц剳鐨勮礋鎷咃紝絎?縐嶅啓娉曪紝蹇樻帀瀹冨惂錛佸疄闄呬笂錛宻izeof璁$畻瀵硅薄鐨勫ぇ灝忎篃鏄漿鎹㈡垚瀵瑰璞$被鍨嬬殑璁$畻錛屼篃灝辨槸璇達紝鍚岀綾誨瀷鐨勪笉鍚屽璞″叾sizeof鍊奸兘鏄竴鑷寸殑銆傝繖閲岋紝瀵硅薄鍙互榪涗竴姝ュ歡浼歌嚦琛ㄨ揪寮忥紝鍗硈izeof鍙互瀵逛竴涓〃杈懼紡姹傚鹼紝緙栬瘧鍣ㄦ牴鎹〃杈懼紡鐨勬渶緇堢粨鏋滅被鍨嬫潵紜畾澶у皬錛屼竴鑸笉浼氬琛ㄨ揪寮忚繘琛岃綆椼傚錛?br>sizeof( 2 ); <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr>// 2鐨勭被鍨嬩負int錛屾墍浠ョ瓑浠蜂簬 sizeof( int );<br>sizeof( 2 + 3.14 ); <wbr> <wbr><span id="hvzpftn" class=Apple-converted-space> </span>// 3.14鐨勭被鍨嬩負double錛?涔熶細琚彁鍗囨垚double綾誨瀷錛屾墍浠ョ瓑浠蜂簬 sizef(double)<br></p> <p style="PADDING-BOTTOM: 0px; LINE-HEIGHT: 21px; BORDER-RIGHT-WIDTH: 0px; LIST-STYLE-TYPE: none; MARGIN: 0px 0px 5px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; WORD-WRAP: normal; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; WORD-BREAK: normal; BORDER-LEFT-WIDTH: 0px; PADDING-TOP: 0px">涔熷彲浠ュ涓涓嚱鏁拌皟鐢ㄦ眰鍊鹼紝鍏剁粨鏋滄槸鍑芥暟榪斿洖綾誨瀷鐨勫ぇ灝忥紝鍑芥暟騫朵笉浼氳璋冪敤錛屾垜浠潵鐪嬩竴涓畬鏁寸殑渚嬪瓙錛?br>char foo()<br>{<br>printf("foo() has been called.\n");<br>return 'a';<br>}<br>int main()<br>{<br>size_t sz = sizeof( foo() ); // foo() 鐨勮繑鍥炲肩被鍨嬩負char錛屾墍浠z = sizeof(char )錛宖oo()騫朵笉浼氳璋冪敤<br>printf("sizeof( foo() ) = %d\n", sz);<br>}<br>C99鏍囧噯瑙勫畾錛屽嚱鏁般佷笉鑳界‘瀹氱被鍨嬬殑琛ㄨ揪寮忎互鍙婁綅鍩燂紙bit-field錛夋垚鍛樹笉鑳借璁$畻sizeof鍊鹼紝鍗充笅闈㈣繖浜涘啓娉曢兘鏄敊璇殑錛?br>sizeof( foo );// error<br>void foo2() { }<br>sizeof( foo2() );// error<br>struct S<br>{<br> <wbr> <wbr><span id="hvzpftn" class=Apple-converted-space> </span> <wbr> <wbr> <wbr><span id="hvzpftn" class=Apple-converted-space> </span>unsigned int f1 : 1;<br> <wbr> <wbr><span id="hvzpftn" class=Apple-converted-space> </span> <wbr> <wbr> <wbr><span id="hvzpftn" class=Apple-converted-space> </span>unsigned int f2 : 5;<br> <wbr> <wbr><span id="hvzpftn" class=Apple-converted-space> </span> <wbr> <wbr> <wbr><span id="hvzpftn" class=Apple-converted-space> </span>unsigned int f3 : 12;<br>};<br>sizeof( S.f1 );// error<br>3. sizeof鐨勫父閲忔?br>sizeof鐨勮綆楀彂鐢熷湪緙栬瘧鏃跺埢錛屾墍浠ュ畠鍙互琚綋浣滃父閲忚〃杈懼紡浣跨敤錛屽錛?br>char ary[ sizeof( int ) * 10 ]; // ok<br>鏈鏂扮殑C99鏍囧噯瑙勫畾sizeof涔熷彲浠ュ湪榪愯鏃跺埢榪涜璁$畻錛屽涓嬮潰鐨勭▼搴忓湪Dev-C++涓彲浠ユ紜墽琛岋細<br>int n;<br>n = 10; // n鍔ㄦ佽祴鍊?br>char ary[n]; // C99涔熸敮鎸佹暟緇勭殑鍔ㄦ佸畾涔?br>printf("%d\n", sizeof(ary)); // ok. 杈撳嚭10<br>浣嗗湪娌℃湁瀹屽叏瀹炵幇C99鏍囧噯鐨勭紪璇戝櫒涓氨琛屼笉閫氫簡錛屼笂闈㈢殑浠g爜鍦╒C6涓氨閫氫笉榪囩紪璇戙傛墍浠ユ垜浠渶濂借繕鏄涓簊izeof鏄湪緙栬瘧鏈熸墽琛岀殑錛岃繖鏍蜂笉浼氬甫鏉ラ敊璇紝璁╃▼搴忕殑鍙Щ妞嶆у己浜涖?br>4. 鍩烘湰鏁版嵁綾誨瀷鐨剆izeof<br>榪欓噷鐨勫熀鏈暟鎹被鍨嬫寚short銆乮nt銆乴ong銆乫loat銆乨ouble榪欐牱鐨勭畝鍗曞唴緗暟鎹被鍨嬶紝鐢變簬瀹冧滑閮芥槸鍜岀郴緇熺浉鍏崇殑錛屾墍浠ュ湪涓嶅悓鐨勭郴緇熶笅鍙栧煎彲鑳戒笉鍚岋紝榪欏姟蹇呭紩璧鋒垜浠殑娉ㄦ剰錛屽敖閲忎笉瑕佸湪榪欐柟闈㈢粰鑷繁紼嬪簭鐨勭Щ妞嶉犳垚楹葷儲銆?br>涓鑸殑錛屽湪32浣嶇紪璇戠幆澧冧腑錛宻izeof(int)鐨勫彇鍊間負4銆?br>5. 鎸囬拡鍙橀噺鐨剆izeof<br>瀛﹁繃鏁版嵁緇撴瀯鐨勪綘搴旇鐭ラ亾鎸囬拡鏄竴涓緢閲嶈鐨勬蹇碉紝瀹冭褰曚簡鍙︿竴涓璞$殑鍦板潃銆傛棦鐒舵槸鏉ュ瓨鏀懼湴鍧鐨勶紝閭d箞瀹冨綋鐒剁瓑浜庤綆楁満鍐呴儴鍦板潃鎬葷嚎鐨勫搴︺傛墍浠ュ湪32浣嶈綆楁満涓紝涓涓寚閽堝彉閲忕殑榪斿洖鍊煎繀瀹氭槸4錛堟敞鎰忕粨鏋滄槸浠ュ瓧鑺備負鍗曚綅錛夛紝鍙互棰勮錛屽湪灝嗘潵鐨?4浣嶇郴緇熶腑鎸囬拡鍙橀噺鐨剆izeof緇撴灉涓?銆?br>char* pc = "abc";<br>int* pi;<br>string* ps;<br>char** ppc = &pc;<br>void (*pf)();// 鍑芥暟鎸囬拡<br>sizeof( pc ); // 緇撴灉涓?<br>sizeof( pi ); // 緇撴灉涓?<br>sizeof( ps ); // 緇撴灉涓?<br>sizeof( ppc ); // 緇撴灉涓?<br>sizeof( pf );// 緇撴灉涓?<br>鎸囬拡鍙橀噺鐨剆izeof鍊間笌鎸囬拡鎵鎸囩殑瀵硅薄娌℃湁浠諱綍鍏崇郴錛屾鏄敱浜庢墍鏈夌殑鎸囬拡鍙橀噺鎵鍗犲唴瀛樺ぇ灝忕浉絳夛紝鎵浠FC娑堟伅澶勭悊鍑芥暟浣跨敤涓や釜鍙傛暟WPARAM銆丩PARAM灝辮兘浼犻掑悇縐嶅鏉傜殑娑堟伅緇撴瀯錛堜嬌鐢ㄦ寚鍚戠粨鏋勪綋鐨勬寚閽堬級銆?br>6. 鏁扮粍鐨剆izeof<br>鏁扮粍鐨剆izeof鍊肩瓑浜庢暟緇勬墍鍗犵敤鐨勫唴瀛樺瓧鑺傛暟錛屽錛?br>char a1[] = "abc";<br>int a2[3];<br>sizeof( a1 ); // 緇撴灉涓?錛屽瓧絎?鏈熬榪樺瓨鍦ㄤ竴涓狽ULL緇堟絎?br>sizeof( a2 ); // 緇撴灉涓?*4=12錛堜緷璧栦簬int錛?br>涓浜涙湅鍙嬪垰寮濮嬫椂鎶妔izeof褰撲綔浜嗘眰鏁扮粍鍏冪礌鐨勪釜鏁幫紝鐜板湪錛屼綘搴旇鐭ラ亾榪欐槸涓嶅鐨勶紝閭d箞搴旇鎬庝箞姹傛暟緇勫厓绱犵殑涓暟鍛asy錛岄氬父鏈変笅闈袱縐嶅啓娉曪細<br>int c1 = sizeof( a1 ) / sizeof( char ); // 鎬婚暱搴?鍗曚釜鍏冪礌鐨勯暱搴?br>int c2 = sizeof( a1 ) / sizeof( a1[0] ); // 鎬婚暱搴?絎竴涓厓绱犵殑闀垮害<br>鍐欏埌榪欓噷錛屾彁涓闂紝涓嬮潰鐨刢3錛宑4鍊煎簲璇ユ槸澶氬皯鍛?br>void foo3(char a3[3])<br>{<br>int c3 = sizeof( a3 ); // c3 ==<br>}<br>void foo4(char a4[])<br>{<br>int c4 = sizeof( a4 ); // c4 ==<br>}<br>涔熻褰撲綘璇曞浘鍥炵瓟c4鐨勫兼椂宸茬粡鎰忚瘑鍒癱3絳旈敊浜嗭紝鏄殑錛宑3!=3銆傝繖閲屽嚱鏁板弬鏁癮3宸蹭笉鍐嶆槸鏁扮粍綾誨瀷錛岃屾槸铚曞彉鎴愭寚閽堬紝鐩稿綋浜巆har* a3錛屼負浠涔堜粩緇嗘兂鎯沖氨涓嶉毦鏄庣櫧錛屾垜浠皟鐢ㄥ嚱鏁癴oo1鏃訛紝紼嬪簭浼氬湪鏍堜笂鍒嗛厤涓涓ぇ灝忎負3鐨勬暟緇勫悧涓嶄細錛佹暟緇勬槸“浼犲潃”鐨勶紝璋冪敤鑰呭彧闇灝嗗疄鍙傜殑鍦板潃浼犻掕繃鍘伙紝鎵浠3鑷劧涓烘寚閽堢被鍨嬶紙char*錛夛紝c3鐨勫間篃灝變負4銆?br>7. 緇撴瀯浣撶殑sizeof<br>榪欐槸鍒濆鑰呴棶寰楁渶澶氱殑涓涓棶棰橈紝鎵浠ヨ繖閲屾湁蹇呰澶氳垂鐐圭瑪澧ㄣ傝鎴戜滑鍏堢湅涓涓粨鏋勪綋錛?br>struct S1<br>{<br>char c;<br>int i;<br>};<br>闂畇izeof(s1)絳変簬澶氬皯鑱槑鐨勪綘寮濮嬫濊冧簡錛宑har鍗?涓瓧鑺傦紝int鍗?涓瓧鑺傦紝閭d箞鍔犺搗鏉ュ氨搴旇鏄?銆傛槸榪欐牱鍚椾綘鍦ㄤ綘鏈哄櫒涓婅瘯榪囦簡鍚椾篃璁鎬綘鏄鐨勶紝浣嗗緢鍙兘浣犳槸閿欑殑錛乂C6涓寜榛樿璁劇疆寰楀埌鐨勭粨鏋滀負8銆?br>Why涓轟粈涔堝彈浼ょ殑鎬繪槸鎴?br>璇蜂笉瑕佹伯涓э紝鎴戜滑鏉ュソ濂界悽紓ㄤ竴涓媠izeof鐨勫畾涔夆斺攕izeof鐨勭粨鏋滅瓑浜庡璞℃垨鑰呯被鍨嬫墍鍗犵殑鍐呭瓨瀛楄妭鏁幫紝濂藉惂錛岄偅灝辮鎴戜滑鏉ョ湅鐪婼1鐨勫唴瀛樺垎閰嶆儏鍐碉細<br>S1 s1 = { 'a', 0xFFFFFFFF };<br>瀹氫箟涓婇潰鐨勫彉閲忓悗錛屽姞涓婃柇鐐癸紝榪愯紼嬪簭錛岃瀵焥1鎵鍦ㄧ殑鍐呭瓨錛屼綘鍙戠幇浜嗕粈涔?br>浠ユ垜鐨刅C6.0涓轟緥錛宻1鐨勫湴鍧涓?x0012FF78錛屽叾鏁版嵁鍐呭濡備笅錛?br>0012FF78: 61 CC CC CC FF FF FF FF<br>鍙戠幇浜嗕粈涔堟庝箞涓棿澶規潅浜?涓瓧鑺傜殑CC鐪嬬湅MSDN涓婄殑璇存槑錛?br>When applied to a structure type or variable, sizeof returns the actual size, which may include padding bytes inserted for alignment.<br>鍘熸潵濡傛錛岃繖灝辨槸浼犺涓殑瀛楄妭瀵歸綈鍟婏紒涓涓噸瑕佺殑璇濋鍑虹幇浜嗐?br>涓轟粈涔堥渶瑕佸瓧鑺傚榻愯綆楁満緇勬垚鍘熺悊鏁欏鎴戜滑榪欐牱鏈夊姪浜庡姞蹇綆楁満鐨勫彇鏁伴熷害錛屽惁鍒欏氨寰楀鑺辨寚浠ゅ懆鏈熶簡銆備負姝わ紝緙栬瘧鍣ㄩ粯璁や細瀵圭粨鏋勪綋榪涜澶勭悊錛堝疄闄呬笂鍏跺畠鍦版柟鐨勬暟鎹彉閲忎篃鏄姝わ級錛岃瀹藉害涓?鐨勫熀鏈暟鎹被鍨嬶紙short絳夛級閮戒綅浜庤兘琚?鏁撮櫎鐨勫湴鍧涓婏紝璁╁搴︿負4鐨勫熀鏈暟鎹被鍨嬶紙int絳夛級閮戒綅浜庤兘琚?鏁撮櫎鐨勫湴鍧涓婏紝浠ユ綾繪帹銆傝繖鏍鳳紝涓や釜鏁頒腑闂村氨鍙兘闇瑕佸姞鍏ュ~鍏呭瓧鑺傦紝鎵浠ユ暣涓粨鏋勪綋鐨剆izeof鍊煎氨澧為暱浜嗐?br>璁╂垜浠氦鎹竴涓婼1涓璫har涓巌nt鐨勪綅緗細<br>struct S2<br>{<br>int i;<br>char c;<br>};<br>鐪嬬湅sizeof(S2)鐨勭粨鏋滀負澶氬皯錛屾庝箞榪樻槸8鍐嶇湅鐪嬪唴瀛橈紝鍘熸潵鎴愬憳c鍚庨潰浠嶇劧鏈?涓~鍏呭瓧鑺傦紝榪欏張鏄負浠涔堝晩鍒潃鎬ワ紝涓嬮潰鎬葷粨瑙勫緥銆?br>瀛楄妭瀵歸綈鐨勭粏鑺傚拰緙栬瘧鍣ㄥ疄鐜扮浉鍏籌紝浣嗕竴鑸岃█錛屾弧瓚充笁涓噯鍒欙細<br>1) 緇撴瀯浣撳彉閲忕殑棣栧湴鍧鑳藉琚叾鏈瀹藉熀鏈被鍨嬫垚鍛樼殑澶у皬鎵鏁撮櫎錛?br>2) 緇撴瀯浣撴瘡涓垚鍛樼浉瀵逛簬緇撴瀯浣撻鍦板潃鐨勫亸縐婚噺錛坥ffset錛夐兘鏄垚鍛樺ぇ灝忕殑鏁存暟鍊嶏紝濡傛湁闇瑕佺紪璇戝櫒浼氬湪鎴愬憳涔嬮棿鍔犱笂濉厖瀛楄妭錛坕nternal adding錛夛紱<br>3) 緇撴瀯浣撶殑鎬誨ぇ灝忎負緇撴瀯浣撴渶瀹藉熀鏈被鍨嬫垚鍛樺ぇ灝忕殑鏁存暟鍊嶏紝濡傛湁闇瑕佺紪璇戝櫒浼氬湪鏈鏈竴涓垚鍛樹箣鍚庡姞涓婂~鍏呭瓧鑺傦紙trailing padding錛夈?br>瀵逛簬涓婇潰鐨勫噯鍒欙紝鏈夊嚑鐐歸渶瑕佽鏄庯細<br>1) 鍓嶉潰涓嶆槸璇寸粨鏋勪綋鎴愬憳鐨勫湴鍧鏄叾澶у皬鐨勬暣鏁板嶏紝鎬庝箞鍙堣鍒板亸縐婚噺浜嗗憿鍥犱負鏈変簡絎?鐐瑰瓨鍦紝鎵浠ユ垜浠氨鍙互鍙冭檻鎴愬憳鐨勫亸縐婚噺錛岃繖鏍鋒濊冭搗鏉ョ畝鍗曘傛兂鎯充負浠涔堛?br>緇撴瀯浣撴煇涓垚鍛樼浉瀵逛簬緇撴瀯浣撻鍦板潃鐨勫亸縐婚噺鍙互閫氳繃瀹弌ffsetof()鏉ヨ幏寰楋紝榪欎釜瀹忎篃鍦╯tddef.h涓畾涔夛紝濡備笅錛?br> <wbr> <wbr><span id="hvzpftn" class=Apple-converted-space> </span>#define offsetof(s,m) (size_t)&(((s *)0)->m)<br>渚嬪錛屾兂瑕佽幏寰桽2涓璫鐨勫亸縐婚噺錛屾柟娉曚負<br>size_t pos = offsetof(S2, c);// pos絳変簬4<br>2) 鍩烘湰綾誨瀷鏄寚鍓嶉潰鎻愬埌鐨勫儚char銆乻hort銆乮nt銆乫loat銆乨ouble榪欐牱鐨勫唴緗暟鎹被鍨嬶紝榪欓噷鎵璇寸殑“鏁版嵁瀹藉害”灝辨槸鎸囧叾sizeof鐨勫ぇ灝忋傜敱浜庣粨鏋勪綋鐨勬垚鍛樺彲浠ユ槸澶嶅悎綾誨瀷錛屾瘮濡傚彟澶栦竴涓粨鏋勪綋錛屾墍浠ュ湪瀵繪壘鏈瀹藉熀鏈被鍨嬫垚鍛樻椂錛屽簲褰撳寘鎷鍚堢被鍨嬫垚鍛樼殑瀛愭垚鍛橈紝鑰屼笉鏄妸澶嶅悎鎴愬憳鐪嬫垚鏄竴涓暣浣撱備絾鍦ㄧ‘瀹氬鍚堢被鍨嬫垚鍛樼殑鍋忕Щ浣嶇疆鏃跺垯鏄皢澶嶅悎綾誨瀷浣滀負鏁翠綋鐪嬪緟銆?br>榪欓噷鍙欒堪璧鋒潵鏈夌偣鎷楀彛錛屾濊冭搗鏉ヤ篃鏈夌偣鎸犲ご錛岃繕鏄鎴戜滑鐪嬬湅渚嬪瓙鍚э紙鍏蜂綋鏁板間粛浠C6涓轟緥錛屼互鍚庝笉鍐嶈鏄庯級錛?br>struct S3<br>{<br>char c1;<br>S1 s;<br>char c2;<br>};<br>S1鐨勬渶瀹界畝鍗曟垚鍛樼殑綾誨瀷涓篿nt錛孲3鍦ㄨ冭檻鏈瀹界畝鍗曠被鍨嬫垚鍛樻椂鏄皢S1“鎵撴暎”鐪嬬殑錛屾墍浠3鐨勬渶瀹界畝鍗曠被鍨嬩負int錛岃繖鏍鳳紝閫氳繃S3瀹氫箟鐨勫彉閲忥紝鍏跺瓨鍌ㄧ┖闂撮鍦板潃闇瑕佽4鏁撮櫎錛屾暣涓猻izeof(S3)鐨勫間篃搴旇琚?鏁撮櫎銆?br>c1鐨勫亸縐婚噺涓?錛宻鐨勫亸縐婚噺鍛㈣繖鏃秙鏄竴涓暣浣擄紝瀹冧綔涓虹粨鏋勪綋鍙橀噺涔熸弧瓚沖墠闈笁涓噯鍒欙紝鎵浠ュ叾澶у皬涓?錛屽亸縐婚噺涓?錛宑1涓巗涔嬮棿渚塊渶瑕?涓~鍏呭瓧鑺傦紝鑰宑2涓巗涔嬮棿灝變笉闇瑕佷簡錛屾墍浠2鐨勫亸縐婚噺涓?2錛岀畻涓奵2鐨勫ぇ灝忎負13錛?3鏄笉鑳借4鏁撮櫎鐨勶紝榪欐牱鏈熬榪樺緱琛ヤ笂3涓~鍏呭瓧鑺傘傛渶鍚庡緱鍒皊izeof(S3)鐨勫間負16銆?br>閫氳繃涓婇潰鐨勫彊榪幫紝鎴戜滑鍙互寰楀埌涓涓叕寮忥細<br>緇撴瀯浣撶殑澶у皬絳変簬鏈鍚庝竴涓垚鍛樼殑鍋忕Щ閲忓姞涓婂叾澶у皬鍐嶅姞涓婃湯灝劇殑濉厖瀛楄妭鏁扮洰錛屽嵆錛?br>sizeof( struct ) = offsetof( last item ) + sizeof( last item ) + sizeof( trailing padding )<br>鍒拌繖閲岋紝鏈嬪弸浠簲璇ュ緇撴瀯浣撶殑sizeof鏈変簡涓涓叏鏂扮殑璁よ瘑錛屼絾涓嶈楂樺叴寰楀お鏃╋紝鏈変竴涓獎鍝峴izeof鐨勯噸瑕佸弬閲忚繕鏈鎻愬強錛岄偅渚挎槸緙栬瘧鍣ㄧ殑pack鎸囦護銆傚畠鏄敤鏉ヨ皟鏁寸粨鏋勪綋瀵歸綈鏂瑰紡鐨勶紝涓嶅悓緙栬瘧鍣ㄥ悕縐板拰鐢ㄦ硶鐣ユ湁涓嶅悓錛孷C6涓氳繃#pragma pack瀹炵幇錛屼篃鍙互鐩存帴淇敼/Zp緙栬瘧寮鍏熾?pragma pack鐨勫熀鏈敤娉曚負錛?pragma pack( n )錛宯涓哄瓧鑺傚榻愭暟錛屽叾鍙栧間負1銆?銆?銆?銆?6錛岄粯璁ゆ槸8錛屽鏋滆繖涓兼瘮緇撴瀯浣撴垚鍛樼殑sizeof鍊煎皬錛岄偅涔?br>璇ユ垚鍛樼殑鍋忕Щ閲忓簲璇ヤ互姝ゅ間負鍑嗭紝鍗蟲槸璇達紝緇撴瀯浣撴垚鍛樼殑鍋忕Щ閲忓簲璇ュ彇浜岃呯殑鏈灝忓鹼紝<br>鍏紡濡備笅錛?br>offsetof( item ) = min( n, sizeof( item ) )<br>鍐嶇湅紺轟緥錛?br>#pragma pack(push) <wbr> <wbr><span id="hvzpftn" class=Apple-converted-space> </span>// 灝嗗綋鍓峱ack璁劇疆鍘嬫爤淇濆瓨<br>#pragma pack(2) // 蹇呴』鍦ㄧ粨鏋勪綋瀹氫箟涔嬪墠浣跨敤<br>struct S1<br>{<br>char c;<br>int i;<br>};<br>struct S3<br>{<br>char c1;<br>S1 s;<br>char c2;<br>};<br>#pragma pack(pop) // 鎭㈠鍏堝墠鐨刾ack璁劇疆<br>璁$畻sizeof(S1)鏃訛紝min(2, sizeof(i))鐨勫間負2錛屾墍浠鐨勫亸縐婚噺涓?錛屽姞涓妔izeof(i)絳変簬6錛岃兘澶熻2鏁撮櫎錛屾墍浠ユ暣涓猄1鐨勫ぇ灝忎負6銆?br>鍚屾牱錛屽浜巗izeof(S3)錛宻鐨勫亸縐婚噺涓?錛宑2鐨勫亸縐婚噺涓?錛屽姞涓妔izeof(c2)絳変簬9錛屼笉鑳借2鏁撮櫎錛屾坊鍔犱竴涓~鍏呭瓧鑺傦紝鎵浠izeof(S3)絳変簬10銆?br><br>鐜板湪錛屾湅鍙嬩滑鍙互杞繪澗鐨勫嚭涓鍙f皵浜嗭紝:)<br>榪樻湁涓鐐硅娉ㄦ剰錛?#8220;絀虹粨鏋勪綋”錛堜笉鍚暟鎹垚鍛橈級鐨勫ぇ灝忎笉涓?錛岃屾槸1銆傝瘯鎯充竴涓?#8220;涓嶅崰絀洪棿”鐨勫彉閲忓浣曡鍙栧湴鍧銆佷袱涓笉鍚岀殑“絀虹粨鏋勪綋”鍙橀噺鍙堝浣曞緱浠ュ尯鍒嗗憿浜庢槸錛?#8220;絀虹粨鏋勪綋”鍙橀噺涔熷緱琚瓨鍌紝榪欐牱緙栬瘧鍣ㄤ篃灝卞彧鑳戒負鍏跺垎閰嶄竴涓瓧鑺傜殑絀洪棿鐢ㄤ簬鍗犱綅浜嗐傚涓嬶細<br>struct S5 { };<br>sizeof( S5 ); // 緇撴灉涓?<br>8. 鍚綅鍩熺粨鏋勪綋鐨剆izeof<br>鍓嶉潰宸茬粡璇磋繃錛屼綅鍩熸垚鍛樹笉鑳藉崟鐙鍙杝izeof鍊鹼紝鎴戜滑榪欓噷瑕佽璁虹殑鏄惈鏈変綅鍩熺殑緇撴瀯浣撶殑sizeof錛屽彧鏄冭檻鍒板叾鐗規畩鎬ц屽皢鍏朵笓闂ㄥ垪浜嗗嚭鏉ャ?br>C99瑙勫畾int銆乽nsigned int鍜宐ool鍙互浣滀負浣嶅煙綾誨瀷錛屼絾緙栬瘧鍣ㄥ嚑涔庨兘瀵規浣滀簡鎵╁睍錛屽厑璁稿叾瀹冪被鍨嬬被鍨嬬殑瀛樺湪銆備嬌鐢ㄤ綅鍩熺殑涓昏鐩殑鏄帇緙╁瓨鍌紝鍏跺ぇ鑷磋鍒欎負錛?br>1) 濡傛灉鐩擱偦浣嶅煙瀛楁鐨勭被鍨嬬浉鍚岋紝涓斿叾浣嶅涔嬪拰灝忎簬綾誨瀷鐨剆izeof澶у皬錛屽垯鍚庨潰鐨勫瓧孌靛皢绱ч偦鍓嶄竴涓瓧孌靛瓨鍌紝鐩村埌涓嶈兘瀹圭撼涓烘錛?br>2) 濡傛灉鐩擱偦浣嶅煙瀛楁鐨勭被鍨嬬浉鍚岋紝浣嗗叾浣嶅涔嬪拰澶т簬綾誨瀷鐨剆izeof澶у皬錛屽垯鍚庨潰鐨勫瓧孌靛皢浠庢柊鐨勫瓨鍌ㄥ崟鍏冨紑濮嬶紝鍏跺亸縐婚噺涓哄叾綾誨瀷澶у皬鐨勬暣鏁板嶏紱<br>3) 濡傛灉鐩擱偦鐨勪綅鍩熷瓧孌電殑綾誨瀷涓嶅悓錛屽垯鍚勭紪璇戝櫒鐨勫叿浣撳疄鐜版湁宸紓錛孷C6閲囧彇涓嶅帇緙╂柟寮忥紝Dev-C++閲囧彇鍘嬬緝鏂瑰紡錛?br>4) 濡傛灉浣嶅煙瀛楁涔嬮棿絀挎彃鐫闈炰綅鍩熷瓧孌碉紝鍒欎笉榪涜鍘嬬緝錛?br>5) 鏁翠釜緇撴瀯浣撶殑鎬誨ぇ灝忎負鏈瀹藉熀鏈被鍨嬫垚鍛樺ぇ灝忕殑鏁存暟鍊嶃?br>榪樻槸璁╂垜浠潵鐪嬬湅渚嬪瓙銆?br>紺轟緥1錛?br>struct BF1<br>{<br>char f1 : 3;<br>char f2 : 4;<br>char f3 : 5;<br>};<br>鍏跺唴瀛樺竷灞涓猴細<br>|_f1__|__f2__|_|____f3___|____|<br>|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|<br>0 3 7 8 1316<br>浣嶅煙綾誨瀷涓篶har錛岀1涓瓧鑺備粎鑳藉綰充笅f1鍜宖2錛屾墍浠2琚帇緙╁埌絎?涓瓧鑺備腑錛岃宖3鍙?br>鑳戒粠涓嬩竴涓瓧鑺傚紑濮嬨傚洜姝izeof(BF1)鐨勭粨鏋滀負2銆?br>紺轟緥2錛?br>struct BF2<br>{<br>char f1 : 3;<br>short f2 : 4;<br>char f3 : 5;<br>};<br>鐢變簬鐩擱偦浣嶅煙綾誨瀷涓嶅悓錛屽湪VC6涓叾sizeof涓?錛屽湪Dev-C++涓負2銆?br>紺轟緥3錛?br>struct BF3<br>{<br>char f1 : 3;<br>char f2;<br>char f3 : 5;<br>};<br>闈炰綅鍩熷瓧孌電┛鎻掑湪鍏朵腑錛屼笉浼氫駭鐢熷帇緙╋紝鍦╒C6鍜孌ev-C++涓緱鍒扮殑澶у皬鍧囦負3銆?br>9. 鑱斿悎浣撶殑sizeof<br>緇撴瀯浣撳湪鍐呭瓨緇勭粐涓婃槸欏哄簭寮忕殑錛岃仈鍚堜綋鍒欐槸閲嶅彔寮忥紝鍚勬垚鍛樺叡浜竴孌靛唴瀛橈紝鎵浠ユ暣涓仈鍚堜綋鐨剆izeof涔熷氨鏄瘡涓垚鍛榮izeof鐨勬渶澶у箋傜粨鏋勪綋鐨勬垚鍛樹篃鍙互鏄鍚堢被鍨嬶紝榪欓噷錛屽鍚堢被鍨嬫垚鍛樻槸琚綔涓烘暣浣撹冭檻鐨勩?br>鎵浠ワ紝涓嬮潰渚嬪瓙涓紝U鐨剆izeof鍊肩瓑浜巗izeof(s)銆?br>union U<br>{<br>int i;<br>char c;<br>S1 s;<br>};<br><br><br>杞嚜錛?a >http://blog.sina.com.cn/s/blog_5af743940100ctd9.html</a></p> </span></span> <img src ="http://www.shnenglu.com/hunter/aggbug/109400.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/hunter/" target="_blank">hunter</a> 2010-03-10 23:36 <a href="http://www.shnenglu.com/hunter/archive/2010/03/10/109400.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>璁℃暟鎺掑簭http://www.shnenglu.com/hunter/archive/2010/03/10/109399.htmlhunterhunterWed, 10 Mar 2010 15:29:00 GMThttp://www.shnenglu.com/hunter/archive/2010/03/10/109399.htmlhttp://www.shnenglu.com/hunter/comments/109399.htmlhttp://www.shnenglu.com/hunter/archive/2010/03/10/109399.html#Feedback0http://www.shnenglu.com/hunter/comments/commentRss/109399.htmlhttp://www.shnenglu.com/hunter/services/trackbacks/109399.html璁℃暟鎺掑簭鐨勫熀鏈濇兂灝辨槸瀵規瘡涓涓緭鍏ュ厓绱燲錛岀‘瀹氬嚭灝忎簬X鐨勫厓绱犱釜鏁般?br>鏈変簡榪欎竴淇℃伅灝卞彲浠ユ妸X鐩存帴鏀懼埌瀹冨湪鏈緇堣緭鍑烘暟緇勪腑鐨勪綅緗笂銆?br>渚嬪錛屽鏋滄湁17涓厓绱犲皬浜嶺錛屽垯X灝卞睘浜庣18涓緭鍑轟綅緗?br>鍦ㄨ鏁版帓搴忕畻娉曠殑浠g爜涓紝鎴戜滑鍋囧畾杈撳叆鏄釜鏁扮粍A[0...n-1]錛宭ength[A]=n銆傚彟澶栬繕闇瑕佷袱涓暟緇勶細瀛樻斁鎺掑簭緇撴灉鐨凚[0...n-1]錛屼互鍙婃彁渚涗復鏃跺瓨鍌ㄥ尯鐨凜[0...k].
#include <stdio.h>
#include 
<stdlib.h>
#include 
<iostream>
using namespace std;

void CountSort(int a[], int b[],int k,int num)
{
    
int* c = new int[k+1];
    
for (int i=0;i<=k;i++)
       c[i]
=0;
    
int size = num;
    
for (int j=0;j<size;j++)
       c[a[j]]
++;
    
//c[i]鍖呭惈絳変簬i鐨勫厓绱犱釜鏁?/span>
    for (i=1;i<=k;i++)
       c[i]
=c[i]+c[i-1];
    
//c[i]鍖呭惈灝忎簬絳変簬i鐨勫厓绱犱釜鏁?/span>
    for (j=size-1;j>=0;j--)
    
{
        b[c[a[j]]
-1]=a[j];
        c[a[j]]
--;
    }


        delete [] c;
}

void main()
{
    
int num,max;
    cout
<<"杈撳叆鏈澶ф暣鏁板強杈撳叆涓暟"<<endl;
    cin
>>max;
    cin
>>num;
    
int* a = new int[num];
    
int* b = new int[num];
    cout
<<"鎺掑簭鍓嶏細"<<endl;
    
for(int i=0;i<num;i++)
    
{
        cin
>>a[i];
        
if (a[i]>max)
            i
--;
    }

        
    CountSort(a,b,max,num);

    cout
<<"鎺掑簭鍚庯細"<<endl;
    
for (int j=0;j<num;j++)
    
{
        cout
<<b[j]<<endl;
    }


    delete [] a;
    delete [] b;
}



hunter 2010-03-10 23:29 鍙戣〃璇勮
]]>
蹇熸帓搴忓強浜屽垎鏌ユ壘http://www.shnenglu.com/hunter/archive/2010/03/09/109321.htmlhunterhunterTue, 09 Mar 2010 14:05:00 GMThttp://www.shnenglu.com/hunter/archive/2010/03/09/109321.htmlhttp://www.shnenglu.com/hunter/comments/109321.htmlhttp://www.shnenglu.com/hunter/archive/2010/03/09/109321.html#Feedback0http://www.shnenglu.com/hunter/comments/commentRss/109321.htmlhttp://www.shnenglu.com/hunter/services/trackbacks/109321.html
#include <stdio.h>
#include 
<stdlib.h>
#include 
<iostream>
using namespace std;

int Partition(int a[],int p,int r)
{
    
int ran=rand()%(r-p+1)+p;       //闅忓嵆閫夊彇鍗叺
    swap(a[ran],a[r]);
    
int x=a[r];
    
int i=p-1;
    
for (int j=p;j<r;j++)
    
{
        
if (a[j]<=x)               //灝忎簬鍗叺鐨勫艱繘琛屽鎹?/span>
        {
            i
++;
            swap(a[i],a[j]);
        }

    }

    swap(a[i
+1],a[r]);
    
return i+1;
}
   

void QuickSort(int a[],int p,int r)
{
    
int q;
    
if (p<r)
    
{
        q
=Partition(a,p,r);
        QuickSort(a,p,q
-1);
        QuickSort(a,q
+1,r);
    }

}


int BinarySearch(int a[],int min,int max,int x)
{
    
int mid;
    
while (min<max)
    
{
        mid
=min+(max-min)/2;
        
if (a[mid]>=x)
            max
=mid;
        
else
            min
=mid+1;     //鑻ヤ笉鍔犱竴鍙兘瀛樺湪鏃犻檺寰幆鐨勭粨鏋?/span>
    }

    
if (a[min]==x)
        
return min;
    
else if(a[max]==x)
        
return max;
    
else
        
return -1;
}

void main()
{
    
int num;
    cin
>>num;
    
int* a = new int[num];
    cout
<<"鎺掑簭鍓嶏細"<<endl;
    
for(int i=0;i<num;i++)
        cin
>>a[i];
    QuickSort(a,
0,num-1);
    cout
<<"鎺掑簭鍚庯細"<<endl;
    
for (int j=0;j<num;j++)
    
{
        cout
<<a[j]<<endl;
    }

    cout
<<"杈撳叆瑕佹煡鎵劇殑鏁?/span>"<<endl;
    
int x;
    cin
>>x;
    
int result=BinarySearch(a,0,num-1,x);
    
if (result>=0)
        cout
<<"鐩爣浣嶇疆涓?"<<result+1<<endl;
    
else
        cout
<<"鐩爣涓嶅湪鏁扮粍涓?/span>"<<endl;
}



hunter 2010-03-09 22:05 鍙戣〃璇勮
]]>
鍫嗘帓搴?/title><link>http://www.shnenglu.com/hunter/archive/2010/03/07/109145.html</link><dc:creator>hunter</dc:creator><author>hunter</author><pubDate>Sun, 07 Mar 2010 14:08:00 GMT</pubDate><guid>http://www.shnenglu.com/hunter/archive/2010/03/07/109145.html</guid><wfw:comment>http://www.shnenglu.com/hunter/comments/109145.html</wfw:comment><comments>http://www.shnenglu.com/hunter/archive/2010/03/07/109145.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/hunter/comments/commentRss/109145.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/hunter/services/trackbacks/109145.html</trackback:ping><description><![CDATA[銆婄畻娉曞璁恒嬩腑鍏稿瀷鐨勬渶澶у爢鎺掑簭<br><br> <div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-SIZE: 13px; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif"><span style="COLOR: #000000">#include </span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">stdio.h</span><span style="COLOR: #000000">></span><span style="COLOR: #000000"><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif">#include </span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">stdlib.h</span><span style="COLOR: #000000">></span><span style="COLOR: #000000"><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif">#include </span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">iostream</span><span style="COLOR: #000000">></span><span style="COLOR: #000000"><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif">#include </span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">vector</span><span style="COLOR: #000000">></span><span style="COLOR: #000000"><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">using</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">namespace</span><span style="COLOR: #000000"> std;<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif"><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif">template</span><span style="COLOR: #000000"><</span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> T</span><span style="COLOR: #000000">></span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> Max_Heap(T a[],</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> i,</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> size)<br><img id=Codehighlighter1_153_410_Open_Image onclick="this.style.display='none'; Codehighlighter1_153_410_Open_Text.style.display='none'; Codehighlighter1_153_410_Closed_Image.style.display='inline'; Codehighlighter1_153_410_Closed_Text.style.display='inline';" align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_153_410_Closed_Image onclick="this.style.display='none'; Codehighlighter1_153_410_Closed_Text.style.display='none'; Codehighlighter1_153_410_Open_Image.style.display='inline'; Codehighlighter1_153_410_Open_Text.style.display='inline';" align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_153_410_Closed_Text><img src="http://www.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_153_410_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> r </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">i </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">;<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> l </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">i </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> largest;<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">    </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (l</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">size </span><span style="COLOR: #000000">&&</span><span style="COLOR: #000000"> a[l]</span><span style="COLOR: #000000">>=</span><span style="COLOR: #000000">a[i])<br><img id=Codehighlighter1_236_254_Open_Image onclick="this.style.display='none'; Codehighlighter1_236_254_Open_Text.style.display='none'; Codehighlighter1_236_254_Closed_Image.style.display='inline'; Codehighlighter1_236_254_Closed_Text.style.display='inline';" align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_236_254_Closed_Image onclick="this.style.display='none'; Codehighlighter1_236_254_Closed_Text.style.display='none'; Codehighlighter1_236_254_Open_Image.style.display='inline'; Codehighlighter1_236_254_Open_Text.style.display='inline';" align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedSubBlock.gif">    </span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_236_254_Closed_Text><img src="http://www.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_236_254_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">        largest </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> l;<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">    }</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">    </span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">        largest </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> i;<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">    </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (r</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">size </span><span style="COLOR: #000000">&&</span><span style="COLOR: #000000"> a[r] </span><span style="COLOR: #000000">>=</span><span style="COLOR: #000000">a[largest])<br><img id=Codehighlighter1_312_330_Open_Image onclick="this.style.display='none'; Codehighlighter1_312_330_Open_Text.style.display='none'; Codehighlighter1_312_330_Closed_Image.style.display='inline'; Codehighlighter1_312_330_Closed_Text.style.display='inline';" align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_312_330_Closed_Image onclick="this.style.display='none'; Codehighlighter1_312_330_Closed_Text.style.display='none'; Codehighlighter1_312_330_Open_Image.style.display='inline'; Codehighlighter1_312_330_Open_Text.style.display='inline';" align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedSubBlock.gif">    </span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_312_330_Closed_Text><img src="http://www.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_312_330_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">        largest </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> r;<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">    }</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">    </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (largest </span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000"> i)<br><img id=Codehighlighter1_352_408_Open_Image onclick="this.style.display='none'; Codehighlighter1_352_408_Open_Text.style.display='none'; Codehighlighter1_352_408_Closed_Image.style.display='inline'; Codehighlighter1_352_408_Closed_Text.style.display='inline';" align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_352_408_Closed_Image onclick="this.style.display='none'; Codehighlighter1_352_408_Closed_Text.style.display='none'; Codehighlighter1_352_408_Open_Image.style.display='inline'; Codehighlighter1_352_408_Open_Text.style.display='inline';" align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedSubBlock.gif">    </span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_352_408_Closed_Text><img src="http://www.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_352_408_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">        swap(a[largest],a[i]);<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">        Max_Heap(a,largest,size);<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">    }</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif"><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif">template</span><span style="COLOR: #000000"><</span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> T</span><span style="COLOR: #000000">></span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> Build_Max_Heap(T a[],</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> size)<br><img id=Codehighlighter1_467_526_Open_Image onclick="this.style.display='none'; Codehighlighter1_467_526_Open_Text.style.display='none'; Codehighlighter1_467_526_Closed_Image.style.display='inline'; Codehighlighter1_467_526_Closed_Text.style.display='inline';" align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_467_526_Closed_Image onclick="this.style.display='none'; Codehighlighter1_467_526_Closed_Text.style.display='none'; Codehighlighter1_467_526_Open_Image.style.display='inline'; Codehighlighter1_467_526_Open_Text.style.display='inline';" align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_467_526_Closed_Text><img src="http://www.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_467_526_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">    </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000"> (</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">size</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000">>=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">)<br><img id=Codehighlighter1_499_524_Open_Image onclick="this.style.display='none'; Codehighlighter1_499_524_Open_Text.style.display='none'; Codehighlighter1_499_524_Closed_Image.style.display='inline'; Codehighlighter1_499_524_Closed_Text.style.display='inline';" align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_499_524_Closed_Image onclick="this.style.display='none'; Codehighlighter1_499_524_Closed_Text.style.display='none'; Codehighlighter1_499_524_Open_Image.style.display='inline'; Codehighlighter1_499_524_Open_Text.style.display='inline';" align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedSubBlock.gif">    </span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_499_524_Closed_Text><img src="http://www.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_499_524_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">        Max_Heap(a,i,size);<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">    }</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif"><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif">template</span><span style="COLOR: #000000"><</span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> T</span><span style="COLOR: #000000">></span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> HeapSort(T a[],</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> size)<br><img id=Codehighlighter1_577_727_Open_Image onclick="this.style.display='none'; Codehighlighter1_577_727_Open_Text.style.display='none'; Codehighlighter1_577_727_Closed_Image.style.display='inline'; Codehighlighter1_577_727_Closed_Text.style.display='inline';" align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_577_727_Closed_Image onclick="this.style.display='none'; Codehighlighter1_577_727_Closed_Text.style.display='none'; Codehighlighter1_577_727_Open_Image.style.display='inline'; Codehighlighter1_577_727_Open_Text.style.display='inline';" align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_577_727_Closed_Text><img src="http://www.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_577_727_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">    Build_Max_Heap(a,size);<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">    </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000"> (</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">size</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000">>=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">)<br><img id=Codehighlighter1_634_725_Open_Image onclick="this.style.display='none'; Codehighlighter1_634_725_Open_Text.style.display='none'; Codehighlighter1_634_725_Closed_Image.style.display='inline'; Codehighlighter1_634_725_Closed_Text.style.display='inline';" align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_634_725_Closed_Image onclick="this.style.display='none'; Codehighlighter1_634_725_Closed_Text.style.display='none'; Codehighlighter1_634_725_Open_Image.style.display='inline'; Codehighlighter1_634_725_Open_Text.style.display='inline';" align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedSubBlock.gif">    </span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_634_725_Closed_Text><img src="http://www.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_634_725_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">        swap(a[i],a[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">]);       </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">灝嗘渶澶ф暟鎹㈠埌鏁扮粍鏈熬<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">        </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">show(a,size);</span><span style="COLOR: #008000"><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif"></span><span style="COLOR: #000000">        size</span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">;<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">        Max_Heap(a,</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,size);<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">    }</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif"><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif">template</span><span style="COLOR: #000000"><</span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> T</span><span style="COLOR: #000000">></span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> show(T a[],</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> size)<br><img id=Codehighlighter1_774_851_Open_Image onclick="this.style.display='none'; Codehighlighter1_774_851_Open_Text.style.display='none'; Codehighlighter1_774_851_Closed_Image.style.display='inline'; Codehighlighter1_774_851_Closed_Text.style.display='inline';" align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_774_851_Closed_Image onclick="this.style.display='none'; Codehighlighter1_774_851_Closed_Text.style.display='none'; Codehighlighter1_774_851_Open_Image.style.display='inline'; Codehighlighter1_774_851_Open_Text.style.display='inline';" align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_774_851_Closed_Text><img src="http://www.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_774_851_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">    cout</span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">鎺掑簭鍚庣粨鏋滀負</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000">endl;<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">    </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000"> (</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">size;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br><img id=Codehighlighter1_826_849_Open_Image onclick="this.style.display='none'; Codehighlighter1_826_849_Open_Text.style.display='none'; Codehighlighter1_826_849_Closed_Image.style.display='inline'; Codehighlighter1_826_849_Closed_Text.style.display='inline';" align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_826_849_Closed_Image onclick="this.style.display='none'; Codehighlighter1_826_849_Closed_Text.style.display='none'; Codehighlighter1_826_849_Open_Image.style.display='inline'; Codehighlighter1_826_849_Open_Text.style.display='inline';" align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedSubBlock.gif">    </span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_826_849_Closed_Text><img src="http://www.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_826_849_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">        cout</span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000">a[i]</span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000">endl;<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">    }</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif"><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> main()<br><img id=Codehighlighter1_865_1068_Open_Image onclick="this.style.display='none'; Codehighlighter1_865_1068_Open_Text.style.display='none'; Codehighlighter1_865_1068_Closed_Image.style.display='inline'; Codehighlighter1_865_1068_Closed_Text.style.display='inline';" align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_865_1068_Closed_Image onclick="this.style.display='none'; Codehighlighter1_865_1068_Closed_Text.style.display='none'; Codehighlighter1_865_1068_Open_Image.style.display='inline'; Codehighlighter1_865_1068_Open_Text.style.display='inline';" align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_865_1068_Closed_Text><img src="http://www.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_865_1068_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> num;<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">    cin</span><span style="COLOR: #000000">>></span><span style="COLOR: #000000">num;<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">    </span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000"> input </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">[num];<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">    </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000"> (</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">num;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br><img id=Codehighlighter1_944_964_Open_Image onclick="this.style.display='none'; Codehighlighter1_944_964_Open_Text.style.display='none'; Codehighlighter1_944_964_Closed_Image.style.display='inline'; Codehighlighter1_944_964_Closed_Text.style.display='inline';" align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_944_964_Closed_Image onclick="this.style.display='none'; Codehighlighter1_944_964_Closed_Text.style.display='none'; Codehighlighter1_944_964_Open_Image.style.display='inline'; Codehighlighter1_944_964_Open_Text.style.display='inline';" align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedSubBlock.gif">    </span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_944_964_Closed_Text><img src="http://www.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_944_964_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">        cin</span><span style="COLOR: #000000">>></span><span style="COLOR: #000000">input[i];<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">    }</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif"><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif"></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">    Build_Max_Heap(input,num);     </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">寤虹珛鏈澶у爢</span><span style="COLOR: #008000"><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif"></span><span style="COLOR: #000000">    HeapSort(input,num);           </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">鍫嗘帓搴?/span><span style="COLOR: #008000"><br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif"></span><span style="COLOR: #000000">    show(input,num);<br><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span></div> <img src ="http://www.shnenglu.com/hunter/aggbug/109145.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/hunter/" target="_blank">hunter</a> 2010-03-07 22:08 <a href="http://www.shnenglu.com/hunter/archive/2010/03/07/109145.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>BMP鏂囦歡緇撴瀯http://www.shnenglu.com/hunter/archive/2009/03/08/75913.htmlhunterhunterSun, 08 Mar 2009 09:06:00 GMThttp://www.shnenglu.com/hunter/archive/2009/03/08/75913.htmlhttp://www.shnenglu.com/hunter/comments/75913.htmlhttp://www.shnenglu.com/hunter/archive/2009/03/08/75913.html#Feedback0http://www.shnenglu.com/hunter/comments/commentRss/75913.htmlhttp://www.shnenglu.com/hunter/services/trackbacks/75913.html
銆銆BMP鏂囦歡鐢辨枃浠跺ご銆佷綅鍥句俊鎭ご銆侀鑹蹭俊鎭拰鍥懼艦鏁版嵁鍥涢儴鍒嗙粍鎴愩傛枃浠跺ご涓昏鍖呭惈鏂囦歡鐨勫ぇ灝忋佹枃浠剁被鍨嬨佸浘鍍忔暟鎹亸紱繪枃浠跺ご鐨勯暱搴︾瓑淇℃伅錛涗綅鍥句俊鎭ご鍖呭惈鍥捐薄鐨勫昂瀵鎬俊鎭佸浘鍍忕敤鍑犱釜姣旂壒鏁板兼潵琛ㄧず涓涓儚绱犮佸浘鍍忔槸鍚﹀帇緙┿佸浘鍍忔墍鐢ㄧ殑棰滆壊鏁扮瓑淇℃伅銆傞鑹蹭俊鎭寘鍚浘鍍忔墍鐢ㄥ埌鐨勯鑹茶〃錛屾樉紺哄浘鍍忔椂闇鐢ㄥ埌榪欎釜棰滆壊琛ㄦ潵鐢熸垚璋冭壊鏉匡紝浣嗗鏋滃浘鍍忎負鐪熷僵鑹詫紝鏃㈠浘鍍忕殑姣忎釜鍍忕礌鐢?4涓瘮鐗規潵琛ㄧず錛屾枃浠朵腑灝辨病鏈夎繖涓鍧椾俊鎭紝涔熷氨涓嶉渶瑕佹搷浣滆皟鑹叉澘銆傛枃浠朵腑鐨勬暟鎹潡琛ㄧず鍥懼儚鐨勭浉搴旂殑鍍忕礌鍊鹼紝闇瑕佹敞鎰忕殑鏄細鍥懼儚鐨勫儚绱犲煎湪鏂囦歡涓殑瀛樻斁欏哄簭涓轟粠宸﹀埌鍙籌紝浠庝笅鍒頒笂錛屼篃灝辨槸璇達紝鍦˙MP鏂囦歡涓鍏堝瓨鏀劇殑鏄浘鍍忕殑鏈鍚庝竴琛屽儚绱狅紝鏈鍚庢墠瀛樺偍鍥懼儚鐨勭涓琛屽儚绱狅紝浣嗗涓庡悓涓琛岀殑鍍忕礌錛屽垯鏄寜鐓у厛宸﹁竟鍚庡彸杈圭殑鐨勯『搴忓瓨鍌ㄧ殑錛涘彟澶栦竴涓渶瑕佽鑰呮湅鍙嬪叧娉ㄧ殑緇嗚妭鏄細鏂囦歡瀛樺偍鍥懼儚鐨勬瘡涓琛屽儚绱犲兼椂錛屽鏋滃瓨鍌ㄨ琛屽儚绱犲兼墍鍗犵殑瀛楄妭鏁頒負4鐨勫嶆暟錛屽垯姝e父瀛樺偍錛屽惁鍒欙紝闇瑕佸湪鍚庣琛?錛屽噾瓚?鐨勫嶆暟銆?

銆銆2. BMP鏂囦歡澶?

銆銆BMP鏂囦歡澶存暟鎹粨鏋勫惈鏈塀MP鏂囦歡鐨勭被鍨嬨佹枃浠跺ぇ灝忓拰浣嶅浘璧峰浣嶇疆絳変俊鎭傚叾緇撴瀯瀹氫箟濡備笅:

typedef struct tagBITMAPFILEHEADER
{
WORD bfType; // 浣嶅浘鏂囦歡鐨勭被鍨嬶紝蹇呴』涓?#8220;BM”
DWORD bfSize; // 浣嶅浘鏂囦歡鐨勫ぇ灝忥紝浠ュ瓧鑺備負鍗曚綅
WORD bfReserved1; // 浣嶅浘鏂囦歡淇濈暀瀛楋紝蹇呴』涓?
WORD bfReserved2; // 浣嶅浘鏂囦歡淇濈暀瀛楋紝蹇呴』涓?
DWORD bfOffBits; // 浣嶅浘鏁版嵁鐨勮搗濮嬩綅緗紝浠ョ浉瀵逛簬浣嶅浘鏂囦歡澶寸殑鍋忕Щ閲忚〃紺猴紝浠ュ瓧鑺備負鍗曚綅
} BITMAPFILEHEADER錛涜緇撴瀯鍗犳嵁14涓瓧鑺傘?

銆銆3. 浣嶅浘淇℃伅澶?

銆銆BMP浣嶅浘淇℃伅澶存暟鎹敤浜庤鏄庝綅鍥劇殑灝哄絳変俊鎭傚叾緇撴瀯濡備笅錛?br>
typedef struct tagBITMAPINFOHEADER{
DWORD biSize; // 鏈粨鏋勬墍鍗犵敤瀛楄妭鏁?br>LONG biWidth; // 浣嶅浘鐨勫搴︼紝浠ュ儚绱犱負鍗曚綅
LONG biHeight; // 浣嶅浘鐨勯珮搴︼紝浠ュ儚绱犱負鍗曚綅
WORD biPlanes; // 鐩爣璁懼鐨勫鉤闈㈡暟涓嶆竻錛屽繀欏諱負1
WORD biBitCount// 姣忎釜鍍忕礌鎵闇鐨勪綅鏁幫紝蹇呴』鏄?(鍙岃壊), 4(16鑹?錛?(256鑹?鎴?4(鐪熷僵鑹?涔嬩竴
DWORD biCompression; // 浣嶅浘鍘嬬緝綾誨瀷錛屽繀欏繪槸 0(涓嶅帇緙?,1(BI_RLE8鍘嬬緝綾誨瀷)鎴?(BI_RLE4鍘嬬緝綾誨瀷)涔嬩竴
DWORD biSizeImage; // 浣嶅浘鐨勫ぇ灝忥紝浠ュ瓧鑺備負鍗曚綅
LONG biXPelsPerMeter; // 浣嶅浘姘村鉤鍒嗚鯨鐜囷紝姣忕背鍍忕礌鏁?br>LONG biYPelsPerMeter; // 浣嶅浘鍨傜洿鍒嗚鯨鐜囷紝姣忕背鍍忕礌鏁?br>DWORD biClrUsed;// 浣嶅浘瀹為檯浣跨敤鐨勯鑹茶〃涓殑棰滆壊鏁?br>DWORD biClrImportant;// 浣嶅浘鏄劇ず榪囩▼涓噸瑕佺殑棰滆壊鏁?br>} BITMAPINFOHEADER錛涜緇撴瀯鍗犳嵁40涓瓧鑺傘?

銆銆娉ㄦ剰錛氬浜嶣MP鏂囦歡鏍煎紡錛屽湪澶勭悊鍗曡壊鍥懼儚鍜岀湡褰╄壊鍥懼儚鐨勬椂鍊欙紝鏃犺鍥捐薄鏁版嵁澶氫箞搴炲ぇ錛岄兘涓嶅鍥捐薄鏁版嵁榪涜浠諱綍鍘嬬緝澶勭悊錛屼竴鑸儏鍐典笅錛屽鏋滀綅鍥鵑噰鐢ㄥ帇緙╂牸寮忥紝閭d箞16鑹插浘鍍忛噰鐢≧LE4鍘嬬緝綆楁硶錛?56鑹插浘鍍忛噰鐢≧LE8鍘嬬緝綆楁硶銆?br>
銆銆4. 棰滆壊琛?

銆銆棰滆壊琛ㄧ敤浜庤鏄庝綅鍥句腑鐨勯鑹詫紝瀹冩湁鑻ュ共涓〃欏癸紝姣忎竴涓〃欏規槸涓涓猂GBQUAD綾誨瀷鐨勭粨鏋勶紝瀹氫箟涓縐嶉鑹層俁GBQUAD緇撴瀯鐨勫畾涔夊涓?

typedef struct tagRGBQUAD {
BYTErgbBlue;// 钃濊壊鐨勪寒搴?鍊艱寖鍥翠負0-255)
BYTErgbGreen; // 緇胯壊鐨勪寒搴?鍊艱寖鍥翠負0-255)
BYTErgbRed; // 綰㈣壊鐨勪寒搴?鍊艱寖鍥翠負0-255)
BYTErgbReserved;// 淇濈暀錛屽繀欏諱負0
} RGBQUAD;

銆銆棰滆壊琛ㄤ腑RGBQUAD緇撴瀯鏁版嵁鐨勪釜鏁扮敱BITMAPINFOHEADER 涓殑biBitCount欏規潵紜畾錛屽綋biBitCount=1,4,8鏃訛紝鍒嗗埆鏈?,16,256涓鑹茶〃欏癸紝褰揵iBitCount=24鏃訛紝鍥懼儚涓虹湡褰╄壊錛屽浘鍍忎腑姣忎釜鍍忕礌鐨勯鑹茬敤涓変釜瀛楄妭琛ㄧず錛屽垎鍒搴擱銆丟銆丅鍊鹼紝鍥懼儚鏂囦歡娌℃湁棰滆壊琛ㄩ」銆備綅鍥句俊鎭ご鍜岄鑹茶〃緇勬垚浣嶅浘淇℃伅錛孊ITMAPINFO緇撴瀯瀹氫箟濡備笅:

typedef struct tagBITMAPINFO {
BITMAPINFOHEADER bmiHeader; // 浣嶅浘淇℃伅澶?br>RGBQUAD bmiColors[1]; // 棰滆壊琛?br>} BITMAPINFO;

銆銆娉ㄦ剰錛歊GBQUAD鏁版嵁緇撴瀯涓紝澧炲姞浜嗕竴涓繚鐣欏瓧孌祌gbReserved錛屽畠涓嶄唬琛ㄤ換浣曢鑹詫紝蹇呴』鍙栧浐瀹氱殑鍊間負“0”錛屽悓鏃訛紝RGBQUAD緇撴瀯涓畾涔夌殑棰滆壊鍊間腑錛岀孩鑹層佺豢鑹插拰钃濊壊鐨勬帓鍒楅『搴忎笌涓鑸湡褰╄壊鍥懼儚鏂囦歡鐨勯鑹叉暟鎹帓鍒楅『搴忔伆濂界浉鍙嶏紝鏃細鑻ユ煇涓綅鍥句腑鐨勪竴涓儚绱犵偣鐨勯鑹茬殑鎻忚堪涓?#8220;00錛?0錛宖f錛?0”錛屽垯琛ㄧず璇ョ偣涓虹孩鑹詫紝鑰屼笉鏄摑鑹層?br>
銆銆5. 浣嶅浘鏁版嵁

銆銆浣嶅浘鏁版嵁璁板綍浜嗕綅鍥劇殑姣忎竴涓儚绱犲兼垨璇ュ搴斿儚绱犵殑棰滆壊琛ㄧ殑绱㈠紩鍊鹼紝鍥懼儚璁板綍欏哄簭鏄湪鎵弿琛屽唴鏄粠宸﹀埌鍙?鎵弿琛屼箣闂存槸浠庝笅鍒頒笂銆傝繖縐嶆牸寮忔垜浠張縐頒負Bottom_Up浣嶅浘錛屽綋鐒朵笌涔嬬浉瀵圭殑榪樻湁Up_Down褰㈠紡鐨勪綅鍥撅紝瀹冪殑璁板綍欏哄簭鏄粠涓婂埌涓嬬殑錛屽浜庤繖縐嶅艦寮忕殑浣嶅浘錛屼篃涓嶅瓨鍦ㄥ帇緙╁艦寮忋備綅鍥劇殑涓涓儚绱犲兼墍鍗犵殑瀛楄妭鏁幫細褰揵iBitCount=1鏃訛紝8涓儚绱犲崰1涓瓧鑺傦紱褰揵iBitCount=4鏃訛紝2涓儚绱犲崰1涓瓧鑺傦紱褰揵iBitCount=8鏃訛紝1涓儚绱犲崰1涓瓧鑺傦紱褰揵iBitCount=24鏃?1涓儚绱犲崰3涓瓧鑺傦紝姝ゆ椂鍥懼儚涓虹湡褰╄壊鍥懼儚銆傚綋鍥懼儚涓嶆槸涓虹湡褰╄壊鏃訛紝鍥懼儚鏂囦歡涓寘鍚鑹茶〃錛屼綅鍥劇殑鏁版嵁琛ㄧず瀵瑰簲鍍忕礌鐐瑰湪棰滆壊琛ㄤ腑鐩稿簲鐨勭儲寮曞鹼紝褰撲負鐪熷僵鑹叉椂錛屾瘡涓涓儚绱犵敤涓変釜瀛楄妭琛ㄧず鍥懼儚鐩稿簲鍍忕礌鐐瑰僵鑹插鹼紝姣忎釜瀛楄妭鍒嗗埆瀵瑰簲R銆丟銆丅鍒嗛噺鐨勫鹼紝榪欐椂鍊欏浘鍍忔枃浠朵腑娌℃湁棰滆壊琛ㄣ備笂闈㈡垜宸茬粡璁茶繃浜嗭紝Windows瑙勫畾鍥懼儚鏂囦歡涓竴涓壂鎻忚鎵鍗犵殑瀛楄妭鏁板繀欏繪槸4鐨勫嶆暟(鍗充互瀛椾負鍗曚綅),涓嶈凍鐨勪互0濉厖錛屽浘鍍忔枃浠朵腑涓涓壂鎻忚鎵鍗犵殑瀛楄妭鏁拌綆楁柟娉曪細

       DataSizePerLine= (biWidth* biBitCount+31)/8錛?/ 涓涓壂鎻忚鎵鍗犵殑瀛楄妭鏁?

鎴栬?br>          DataSizePerLine= (biWidth* biBitCount+31)/32 * 4錛?/ 涓涓壂鎻忚鎵鍗犵殑瀛楄妭鏁?/strong>

(濡傛灉biBitCount == 8 鎴?4)

         DataSizePerLine= (biWidth* 3+3)/4*4錛?/ 涓涓壂鎻忚鎵鍗犵殑瀛楄妭鏁?

鎴?/p>

       DataSizePerLine= (biWidth*1+3)/4*4錛?/ 涓涓壂鎻忚鎵鍗犵殑瀛楄妭鏁?
銆銆浣嶅浘鏁版嵁鐨勫ぇ灝忔寜涓嬪紡璁$畻(涓嶅帇緙╂儏鍐典笅)錛?br>
銆銆DataSize= DataSizePerLine* biHeight銆?

銆銆涓婅堪鏄疊MP鏂囦歡鏍煎紡鐨勮鏄庯紝鎼炴竻妤氫簡浠ヤ笂鐨勭粨鏋勶紝灝卞彲浠ユ紜殑鎿嶄綔鍥懼儚鏂囦歡錛屽瀹冭繘琛岃鎴栧啓鎿嶄綔浜嗐?br>
杞嚜http://hi.baidu.com/kennlee/blog/item/52375eca63394743f31fe7d8.html



hunter 2009-03-08 17:06 鍙戣〃璇勮
]]>
ACM 2402 Palindrome Numershttp://www.shnenglu.com/hunter/archive/2008/12/01/68255.htmlhunterhunterSun, 30 Nov 2008 17:28:00 GMThttp://www.shnenglu.com/hunter/archive/2008/12/01/68255.htmlhttp://www.shnenglu.com/hunter/comments/68255.htmlhttp://www.shnenglu.com/hunter/archive/2008/12/01/68255.html#Feedback0http://www.shnenglu.com/hunter/comments/commentRss/68255.htmlhttp://www.shnenglu.com/hunter/services/trackbacks/68255.html闃呰鍏ㄦ枃

hunter 2008-12-01 01:28 鍙戣〃璇勮
]]>
ACM 2325 Persistent Number 澶ф暟鐩擱櫎http://www.shnenglu.com/hunter/archive/2008/11/30/68229.htmlhunterhunterSun, 30 Nov 2008 12:30:00 GMThttp://www.shnenglu.com/hunter/archive/2008/11/30/68229.htmlhttp://www.shnenglu.com/hunter/comments/68229.htmlhttp://www.shnenglu.com/hunter/archive/2008/11/30/68229.html#Feedback2http://www.shnenglu.com/hunter/comments/commentRss/68229.htmlhttp://www.shnenglu.com/hunter/services/trackbacks/68229.html
涓嬮潰鏄煇澶уぇ鐨勪唬鐮侊紝鎬濊礬灝辨槸浠?鍒?涓壘鍑鴻兘琚玁鏁撮櫎鐨勬暟錛岀劧鍚庢墦鍗板嚭鏈灝忕殑緇勫悎

澶ф暟鐩擱偅涓孌靛緢鍊煎緱瀛︿範錛?br>
#include <iostream>
#include 
<string>
#include 
<vector>
#include 
<cmath>
using namespace std;

#define  MAXCHAR 1002

void Div(char *ch1, char *ch2, char *ch3) {
    
char temp[MAXCHAR];
    
int i;
    memset(ch3,
0,sizeof(ch3));
    
int num=ch2[0]-'0';
    
int len=strlen(ch1);
    
int s=0;
    
for(i=0;i<len;i++){       //澶ф暟鐩擱櫎
        s=s*10+ch1[i]-'0';
        ch3[i]
=s/num+'0';
        s
%=num;
    }

    
int flag=0;
    
int j=0;
    
for(i=0;i<len;i++){
        
if(flag==0&&ch3[i]=='0')
            
continue;
        flag
=1;
        temp[j]
=ch3[i];
        j
++;
    }

    temp[j]
='\0';
    strcpy(ch3,temp);
}

bool op(char *num,int t){
    
int len=strlen(num);
    
int i,j,k;
    k
=0;
    
for(i=0;i<len;i++){
        k
=k*10+num[i]-'0';
        k
=k%t;
    }

    
if(k==0)
        
return true;
    
else
        
return false;
}

int main() {
    
char num[MAXCHAR], s[300];
    
char temp[MAXCHAR];
    
char aaa[MAXCHAR];
    
int i, j;
    
int ans[10][2];
    
while (1{
        scanf(
"%s"&num);
        
if(num[1]=='\0'){
            printf(
"1%c\n",num[0]);
            
continue;
        }

        memset(ans, 
0sizeof (ans));
        
if (num[0== '-')
            
break;
        
for (i = 9; i >= 2; i--{
            s[
0]=i+'0';
            s[
1]='\0';
            strcpy(temp, num);           
            
while (1{
                
if (op(temp,i) ) {
                    Div(temp,s,aaa);
                    strcpy(num,aaa);
                    ans[i][
0]=1;
                    ans[i][
1]++;
                    strcpy(temp,num);
                }

                
else
                    
break;
            }

            
if(num[1]=='\0')
                
break;
        }

        
if(num[1]!='\0'){
            printf(
"There is no such number.\n");
            
continue;
        }

        ans[num[
0]-'0'][0]=1;
        ans[num[
0]-'0'][1]++;
        
for (i = 2; i < 10; i++{
            
if (ans[i][0= 1{
                
for (j = 0; j < ans[i][1]; j++)
                    printf(
"%d", i);
            }

        }

        printf(
"\n");
    }

    
return 0;
}



hunter 2008-11-30 20:30 鍙戣〃璇勮
]]>
ACM 2316 SPINhttp://www.shnenglu.com/hunter/archive/2008/11/30/68203.htmlhunterhunterSat, 29 Nov 2008 18:44:00 GMThttp://www.shnenglu.com/hunter/archive/2008/11/30/68203.htmlhttp://www.shnenglu.com/hunter/comments/68203.htmlhttp://www.shnenglu.com/hunter/archive/2008/11/30/68203.html#Feedback2http://www.shnenglu.com/hunter/comments/commentRss/68203.htmlhttp://www.shnenglu.com/hunter/services/trackbacks/68203.htmlEOF鑷繁杈撳叆浠涔堬紵

#include <iostream>
#include 
<string>
#include 
<vector>
#include 
<cmath>
using namespace std;

int main()
{
    
char input[15];char result[15];
    
int len;
    scanf(
"%s",result);
    
while (scanf("%s",input)!=EOF)
    
{
        len
=strlen(input);
        
        
for (int i=0;i<len;i++)
        
{
            result[i]
=(result[i]-'0'+input[i]-'0')%10+'0';
        }

    }

    printf(
"%s",result);
}




hunter 2008-11-30 02:44 鍙戣〃璇勮
]]>
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            最新国产乱人伦偷精品免费网站| 国产欧美日韩麻豆91| 亚洲欧美日韩在线| 亚洲国产一区二区三区青草影视| 午夜亚洲性色福利视频| 亚洲国产精品久久久| 国产欧美一区二区精品性色| 欧美日韩色综合| 乱码第一页成人| 久久国产精品99精品国产| 亚洲一二三区在线| 欧美激情按摩| 久久综合一区| 欧美在线观看一区| 亚洲免费在线电影| 中文在线资源观看网站视频免费不卡 | 亚洲一区二区三区免费在线观看| 亚洲国产成人av在线| 美女999久久久精品视频| 欧美在线不卡| 欧美一区二区在线视频| 亚洲综合999| 亚洲图片你懂的| 99精品国产福利在线观看免费| 在线精品亚洲| 黄色成人av网| 伊人一区二区三区久久精品| 韩国一区二区三区在线观看 | 久久精品亚洲乱码伦伦中文| 香蕉国产精品偷在线观看不卡| 亚洲午夜精品久久| 亚洲图片欧洲图片av| 亚洲最新视频在线播放| 一区二区三区精密机械公司| 亚洲伦理网站| 一区二区三区欧美在线| 亚洲无玛一区| 亚洲综合日本| 欧美在线影院| 久久免费少妇高潮久久精品99| 久久国产免费看| 久久嫩草精品久久久精品一| 久久婷婷久久| 亚洲大黄网站| 日韩一本二本av| 亚洲一区影院| 久久久www| 欧美成人免费小视频| 欧美日韩亚洲国产一区| 国产精品夜夜嗨| 国产有码在线一区二区视频| 欲香欲色天天天综合和网| 亚洲欧洲一区二区在线播放 | 亚洲影视中文字幕| 欧美一区激情| 免费视频亚洲| 欧美性大战久久久久久久蜜臀| 国产精品久久国产三级国电话系列| 国产精品日本| 在线精品福利| 亚洲午夜视频在线观看| 久久精品成人一区二区三区蜜臀| 蜜乳av另类精品一区二区| 最新热久久免费视频| 亚洲一区国产一区| 老司机亚洲精品| 欧美日韩一区二区三区视频| 国产视频欧美视频| 亚洲激情在线观看视频免费| 亚洲午夜精品国产| 久久综合色8888| 亚洲美洲欧洲综合国产一区| 亚洲欧美日韩人成在线播放| 免费日韩成人| 国产精品爽黄69| 亚洲欧洲一区| 久久精品国产清高在天天线| 亚洲国产经典视频| 小黄鸭精品密入口导航| 欧美二区在线| 国产午夜精品在线| aa级大片欧美三级| 美女脱光内衣内裤视频久久网站| 亚洲免费观看视频| 久久精品色图| 国产精品不卡在线| 亚洲人成网站色ww在线| 久久成人一区二区| 亚洲激情国产| 久久精品人人做人人综合| 国产精品第十页| 亚洲欧洲一区| 玖玖玖免费嫩草在线影院一区| 99精品国产热久久91蜜凸| 久久综合国产精品| 国产性做久久久久久| 一区二区三区波多野结衣在线观看| 噜噜噜躁狠狠躁狠狠精品视频 | 蜜桃久久av一区| 国产日韩欧美视频| 亚洲视频在线观看免费| 亚洲大胆av| 久久久之久亚州精品露出| 国产精品热久久久久夜色精品三区| 亚洲蜜桃精久久久久久久| 久久视频一区二区| 亚洲欧美日韩电影| 国产精品vvv| 99热在线精品观看| 亚洲第一精品久久忘忧草社区| 久久99在线观看| 国产欧美日本一区视频| 欧美亚洲一级| 在线亚洲免费视频| 欧美四级电影网站| 亚洲午夜激情免费视频| 亚洲精品老司机| 欧美高清免费| 日韩视频一区二区在线观看 | 亚洲视频在线播放| 欧美视频日韩| 亚洲先锋成人| 一区二区激情| 欧美特黄视频| 午夜精品久久久| 亚洲一区二区在线播放| 国产精品裸体一区二区三区| 亚洲综合二区| 亚洲综合欧美日韩| 国产三级精品三级| 久久久久久成人| 久久精品视频在线看| 狠狠综合久久av一区二区老牛| 久久久久久久一区二区| 久久婷婷人人澡人人喊人人爽| 在线观看一区| 欧美激情在线观看| 欧美交受高潮1| 亚洲直播在线一区| 亚洲影院在线| 激情小说亚洲一区| 亚洲大片在线观看| 欧美日韩高清一区| 亚洲在线一区二区| 午夜精品久久久久久99热软件| 国产日韩亚洲欧美| 美女国产一区| 欧美劲爆第一页| 亚洲欧美日韩另类精品一区二区三区| 亚洲视频欧美在线| 国产色综合天天综合网| 欧美成人免费在线| 欧美日韩国产综合新一区| 亚洲欧美春色| 久久精品视频播放| 亚洲伦伦在线| 亚洲欧美春色| 亚洲国产第一| aa级大片欧美三级| 国产一区二区高清不卡| 欧美黄色小视频| 欧美四级在线观看| 久久久久久一区二区三区| 欧美阿v一级看视频| 亚洲一区二区三区在线视频| 欧美亚洲一区三区| 亚洲乱码国产乱码精品精98午夜 | 久久精品在这里| 日韩一区二区福利| 欧美一区高清| 99这里只有精品| 欧美在线看片a免费观看| 亚洲日本一区二区| 亚洲欧美国产日韩天堂区| 91久久精品视频| 亚洲欧美视频一区| 亚洲美女91| 欧美一区二视频在线免费观看| 亚洲麻豆一区| 欧美主播一区二区三区美女 久久精品人| 亚洲国产成人一区| 亚洲欧美中文另类| 日韩亚洲欧美一区二区三区| 欧美一区二区视频在线观看2020| 99精品国产高清一区二区| 欧美中文字幕不卡| 亚洲主播在线播放| 欧美岛国激情| 免费成人你懂的| 国产日产高清欧美一区二区三区| 亚洲欧洲一二三| 一区二区在线观看视频| 亚洲欧美日韩系列| 亚洲视频大全| 欧美激情综合在线| 免费一级欧美片在线播放| 国产九色精品成人porny| 亚洲精品美女| 亚洲肉体裸体xxxx137| 欧美影院久久久|