锘??xml version="1.0" encoding="utf-8" standalone="yes"?> C璇█涓垽鏂暟鎹被鍨嬮暱搴︾ 涔熷彲浠ュ涓涓嚱鏁拌皟鐢ㄦ眰鍊鹼紝鍏剁粨鏋滄槸鍑芥暟榪斿洖綾誨瀷鐨勫ぇ灝忥紝鍑芥暟騫朵笉浼氳璋冪敤錛屾垜浠潵鐪嬩竴涓畬鏁寸殑渚嬪瓙錛?br>char foo() 鎴栬?br> DataSizePerLine= (biWidth* biBitCount+31)/32 * 4錛?/ 涓涓壂鎻忚鎵鍗犵殑瀛楄妭鏁?/strong> (濡傛灉biBitCount == 8 鎴?4) DataSizePerLine= (biWidth* 3+3)/4*4錛?/ 涓涓壂鎻忚鎵鍗犵殑瀛楄妭鏁? 鎴?/p>
DataSizePerLine= (biWidth*1+3)/4*4錛?/ 涓涓壂鎻忚鎵鍗犵殑瀛楄妭鏁?
#include
#include
#include
using namespace std;
錛?錛夊垱寤轟竴涓暟緇勶紝
v_Arry.pus
v_Arry.pus
v_Arry.pus
v_Arry.pus
v_Arry.pus
v_Arry.pus
v_Arry.pus
v_Arry.pus
v_Arry.pus
v_Arry.pus
v_Arry.pus
錛?錛塵ake_he
錛?錛夋鏃跺彲浠ヨ緭鍑烘煡
鍙樻垚浜屽弶鏍戝氨鏄涓嬶細
v_Arry.pop
浜屽弶鏍戝涓嬶細
錛?錛塿_Arry.
姝ゆ椂杈撳嚭緇撴灉錛?5錛?wbr>10錛?錛?錛?錛?
浜屽弶鏍戝涓嬶細
錛?錛塻ort_he
錛?錛塮ind ( v_Arry.beg
鍘熸枃鍦板潃錛?a >http://blog.zol.com.cn/1356/article_1355249.html
]]>
#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;
}
]]>
鐢ㄦ硶
鎴?br>
1. 瀹氫箟錛?br>sizeof鏄疌/C++涓殑涓涓搷浣滅錛坥perator錛夋槸涔燂紝綆鍗曠殑璇村叾浣滅敤灝辨槸榪斿洖涓涓璞℃垨鑰呯被鍨嬫墍鍗犵殑鍐呭瓨瀛楄妭鏁般?br>MSDN涓婄殑瑙i噴涓猴細
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.
鍏惰繑鍥炲肩被鍨嬩負size_t錛屽湪澶存枃浠秙tddef.h涓畾涔夈傝繖鏄竴涓緷璧栦簬緙栬瘧緋葷粺鐨勫鹼紝涓鑸畾涔変負
typedef unsigned int size_t;
涓栦笂緙栬瘧鍣ㄦ灄鏋楁繪伙紝浣嗕綔涓轟竴涓鑼冿紝瀹冧滑閮戒細淇濊瘉char銆乻igned char鍜寀nsigned
char鐨剆izeof鍊間負1錛屾瘯绔焎har鏄垜浠紪紼嬭兘鐢ㄧ殑鏈灝忔暟鎹被鍨嬨?br>2. 璇硶錛?br>sizeof鏈変笁縐嶈娉曞艦寮忥紝濡備笅錛?br>1) sizeof( object ); // sizeof( 瀵硅薄 );
2) sizeof( type_name ); // sizeof( 綾誨瀷 );
3) sizeof object; // sizeof 瀵硅薄;
鎵浠ワ紝
int i;
sizeof( i );
sizeof i;
sizeof( int ); // ok
sizeof int;
鏃㈢劧鍐欐硶3鍙互鐢ㄥ啓娉?浠f浛錛屼負姹傚艦寮忕粺涓浠ュ強鍑忓皯鎴戜滑澶ц剳鐨勮礋鎷咃紝絎?縐嶅啓娉曪紝蹇樻帀瀹冨惂錛佸疄闄呬笂錛宻izeof璁$畻瀵硅薄鐨勫ぇ灝忎篃鏄漿鎹㈡垚瀵瑰璞$被鍨嬬殑璁$畻錛屼篃灝辨槸璇達紝鍚岀綾誨瀷鐨勪笉鍚屽璞″叾sizeof鍊奸兘鏄竴鑷寸殑銆傝繖閲岋紝瀵硅薄鍙互榪涗竴姝ュ歡浼歌嚦琛ㄨ揪寮忥紝鍗硈izeof鍙互瀵逛竴涓〃杈懼紡姹傚鹼紝緙栬瘧鍣ㄦ牴鎹〃杈懼紡鐨勬渶緇堢粨鏋滅被鍨嬫潵紜畾澶у皬錛屼竴鑸笉浼氬琛ㄨ揪寮忚繘琛岃綆椼傚錛?br>sizeof( 2 );
sizeof( 2 + 3.14 );
{
printf("foo() has been called.\n");
return 'a';
}
int main()
{
size_t sz = sizeof( foo() ); // foo() 鐨勮繑鍥炲肩被鍨嬩負char錛屾墍浠z = sizeof(char )錛宖oo()騫朵笉浼氳璋冪敤
printf("sizeof( foo() ) = %d\n", sz);
}
C99鏍囧噯瑙勫畾錛屽嚱鏁般佷笉鑳界‘瀹氱被鍨嬬殑琛ㄨ揪寮忎互鍙婁綅鍩燂紙bit-field錛夋垚鍛樹笉鑳借璁$畻sizeof鍊鹼紝鍗充笅闈㈣繖浜涘啓娉曢兘鏄敊璇殑錛?br>sizeof( foo );// error
void foo2() { }
sizeof( foo2() );// error
struct S
{
};
sizeof( S.f1 );// error
3. sizeof鐨勫父閲忔?br>sizeof鐨勮綆楀彂鐢熷湪緙栬瘧鏃跺埢錛屾墍浠ュ畠鍙互琚綋浣滃父閲忚〃杈懼紡浣跨敤錛屽錛?br>char ary[ sizeof( int ) * 10 ]; // ok
鏈鏂扮殑C99鏍囧噯瑙勫畾sizeof涔熷彲浠ュ湪榪愯鏃跺埢榪涜璁$畻錛屽涓嬮潰鐨勭▼搴忓湪Dev-C++涓彲浠ユ紜墽琛岋細
int n;
n = 10; // n鍔ㄦ佽祴鍊?br>char ary[n]; // C99涔熸敮鎸佹暟緇勭殑鍔ㄦ佸畾涔?br>printf("%d\n", sizeof(ary)); // ok. 杈撳嚭10
浣嗗湪娌℃湁瀹屽叏瀹炵幇C99鏍囧噯鐨勭紪璇戝櫒涓氨琛屼笉閫氫簡錛屼笂闈㈢殑浠g爜鍦╒C6涓氨閫氫笉榪囩紪璇戙傛墍浠ユ垜浠渶濂借繕鏄涓簊izeof鏄湪緙栬瘧鏈熸墽琛岀殑錛岃繖鏍蜂笉浼氬甫鏉ラ敊璇紝璁╃▼搴忕殑鍙Щ妞嶆у己浜涖?br>4. 鍩烘湰鏁版嵁綾誨瀷鐨剆izeof
榪欓噷鐨勫熀鏈暟鎹被鍨嬫寚short銆乮nt銆乴ong銆乫loat銆乨ouble榪欐牱鐨勭畝鍗曞唴緗暟鎹被鍨嬶紝鐢變簬瀹冧滑閮芥槸鍜岀郴緇熺浉鍏崇殑錛屾墍浠ュ湪涓嶅悓鐨勭郴緇熶笅鍙栧煎彲鑳戒笉鍚岋紝榪欏姟蹇呭紩璧鋒垜浠殑娉ㄦ剰錛屽敖閲忎笉瑕佸湪榪欐柟闈㈢粰鑷繁紼嬪簭鐨勭Щ妞嶉犳垚楹葷儲銆?br>涓鑸殑錛屽湪32浣嶇紪璇戠幆澧冧腑錛宻izeof(int)鐨勫彇鍊間負4銆?br>5. 鎸囬拡鍙橀噺鐨剆izeof
瀛﹁繃鏁版嵁緇撴瀯鐨勪綘搴旇鐭ラ亾鎸囬拡鏄竴涓緢閲嶈鐨勬蹇碉紝瀹冭褰曚簡鍙︿竴涓璞$殑鍦板潃銆傛棦鐒舵槸鏉ュ瓨鏀懼湴鍧鐨勶紝閭d箞瀹冨綋鐒剁瓑浜庤綆楁満鍐呴儴鍦板潃鎬葷嚎鐨勫搴︺傛墍浠ュ湪32浣嶈綆楁満涓紝涓涓寚閽堝彉閲忕殑榪斿洖鍊煎繀瀹氭槸4錛堟敞鎰忕粨鏋滄槸浠ュ瓧鑺備負鍗曚綅錛夛紝鍙互棰勮錛屽湪灝嗘潵鐨?4浣嶇郴緇熶腑鎸囬拡鍙橀噺鐨剆izeof緇撴灉涓?銆?br>char* pc = "abc";
int* pi;
string* ps;
char** ppc = &pc;
void (*pf)();// 鍑芥暟鎸囬拡
sizeof( pc ); // 緇撴灉涓?
sizeof( pi ); // 緇撴灉涓?
sizeof( ps ); // 緇撴灉涓?
sizeof( ppc ); // 緇撴灉涓?
sizeof( pf );// 緇撴灉涓?
鎸囬拡鍙橀噺鐨剆izeof鍊間笌鎸囬拡鎵鎸囩殑瀵硅薄娌℃湁浠諱綍鍏崇郴錛屾鏄敱浜庢墍鏈夌殑鎸囬拡鍙橀噺鎵鍗犲唴瀛樺ぇ灝忕浉絳夛紝鎵浠FC娑堟伅澶勭悊鍑芥暟浣跨敤涓や釜鍙傛暟WPARAM銆丩PARAM灝辮兘浼犻掑悇縐嶅鏉傜殑娑堟伅緇撴瀯錛堜嬌鐢ㄦ寚鍚戠粨鏋勪綋鐨勬寚閽堬級銆?br>6. 鏁扮粍鐨剆izeof
鏁扮粍鐨剆izeof鍊肩瓑浜庢暟緇勬墍鍗犵敤鐨勫唴瀛樺瓧鑺傛暟錛屽錛?br>char a1[] = "abc";
int a2[3];
sizeof( a1 ); // 緇撴灉涓?錛屽瓧絎?鏈熬榪樺瓨鍦ㄤ竴涓狽ULL緇堟絎?br>sizeof( a2 ); // 緇撴灉涓?*4=12錛堜緷璧栦簬int錛?br>涓浜涙湅鍙嬪垰寮濮嬫椂鎶妔izeof褰撲綔浜嗘眰鏁扮粍鍏冪礌鐨勪釜鏁幫紝鐜板湪錛屼綘搴旇鐭ラ亾榪欐槸涓嶅鐨勶紝閭d箞搴旇鎬庝箞姹傛暟緇勫厓绱犵殑涓暟鍛asy錛岄氬父鏈変笅闈袱縐嶅啓娉曪細
int c1 = sizeof( a1 ) / sizeof( char ); // 鎬婚暱搴?鍗曚釜鍏冪礌鐨勯暱搴?br>int c2 = sizeof( a1 ) / sizeof( a1[0] ); // 鎬婚暱搴?絎竴涓厓绱犵殑闀垮害
鍐欏埌榪欓噷錛屾彁涓闂紝涓嬮潰鐨刢3錛宑4鍊煎簲璇ユ槸澶氬皯鍛?br>void foo3(char a3[3])
{
int c3 = sizeof( a3 ); // c3 ==
}
void foo4(char a4[])
{
int c4 = sizeof( a4 ); // c4 ==
}
涔熻褰撲綘璇曞浘鍥炵瓟c4鐨勫兼椂宸茬粡鎰忚瘑鍒癱3絳旈敊浜嗭紝鏄殑錛宑3!=3銆傝繖閲屽嚱鏁板弬鏁癮3宸蹭笉鍐嶆槸鏁扮粍綾誨瀷錛岃屾槸铚曞彉鎴愭寚閽堬紝鐩稿綋浜巆har* a3錛屼負浠涔堜粩緇嗘兂鎯沖氨涓嶉毦鏄庣櫧錛屾垜浠皟鐢ㄥ嚱鏁癴oo1鏃訛紝紼嬪簭浼氬湪鏍堜笂鍒嗛厤涓涓ぇ灝忎負3鐨勬暟緇勫悧涓嶄細錛佹暟緇勬槸“浼犲潃”鐨勶紝璋冪敤鑰呭彧闇灝嗗疄鍙傜殑鍦板潃浼犻掕繃鍘伙紝鎵浠3鑷劧涓烘寚閽堢被鍨嬶紙char*錛夛紝c3鐨勫間篃灝變負4銆?br>7. 緇撴瀯浣撶殑sizeof
榪欐槸鍒濆鑰呴棶寰楁渶澶氱殑涓涓棶棰橈紝鎵浠ヨ繖閲屾湁蹇呰澶氳垂鐐圭瑪澧ㄣ傝鎴戜滑鍏堢湅涓涓粨鏋勪綋錛?br>struct S1
{
char c;
int i;
};
闂畇izeof(s1)絳変簬澶氬皯鑱槑鐨勪綘寮濮嬫濊冧簡錛宑har鍗?涓瓧鑺傦紝int鍗?涓瓧鑺傦紝閭d箞鍔犺搗鏉ュ氨搴旇鏄?銆傛槸榪欐牱鍚椾綘鍦ㄤ綘鏈哄櫒涓婅瘯榪囦簡鍚椾篃璁鎬綘鏄鐨勶紝浣嗗緢鍙兘浣犳槸閿欑殑錛乂C6涓寜榛樿璁劇疆寰楀埌鐨勭粨鏋滀負8銆?br>Why涓轟粈涔堝彈浼ょ殑鎬繪槸鎴?br>璇蜂笉瑕佹伯涓э紝鎴戜滑鏉ュソ濂界悽紓ㄤ竴涓媠izeof鐨勫畾涔夆斺攕izeof鐨勭粨鏋滅瓑浜庡璞℃垨鑰呯被鍨嬫墍鍗犵殑鍐呭瓨瀛楄妭鏁幫紝濂藉惂錛岄偅灝辮鎴戜滑鏉ョ湅鐪婼1鐨勫唴瀛樺垎閰嶆儏鍐碉細
S1 s1 = { 'a', 0xFFFFFFFF };
瀹氫箟涓婇潰鐨勫彉閲忓悗錛屽姞涓婃柇鐐癸紝榪愯紼嬪簭錛岃瀵焥1鎵鍦ㄧ殑鍐呭瓨錛屼綘鍙戠幇浜嗕粈涔?br>浠ユ垜鐨刅C6.0涓轟緥錛宻1鐨勫湴鍧涓?x0012FF78錛屽叾鏁版嵁鍐呭濡備笅錛?br>0012FF78: 61 CC CC CC FF FF FF FF
鍙戠幇浜嗕粈涔堟庝箞涓棿澶規潅浜?涓瓧鑺傜殑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>涓轟粈涔堥渶瑕佸瓧鑺傚榻愯綆楁満緇勬垚鍘熺悊鏁欏鎴戜滑榪欐牱鏈夊姪浜庡姞蹇綆楁満鐨勫彇鏁伴熷害錛屽惁鍒欏氨寰楀鑺辨寚浠ゅ懆鏈熶簡銆備負姝わ紝緙栬瘧鍣ㄩ粯璁や細瀵圭粨鏋勪綋榪涜澶勭悊錛堝疄闄呬笂鍏跺畠鍦版柟鐨勬暟鎹彉閲忎篃鏄姝わ級錛岃瀹藉害涓?鐨勫熀鏈暟鎹被鍨嬶紙short絳夛級閮戒綅浜庤兘琚?鏁撮櫎鐨勫湴鍧涓婏紝璁╁搴︿負4鐨勫熀鏈暟鎹被鍨嬶紙int絳夛級閮戒綅浜庤兘琚?鏁撮櫎鐨勫湴鍧涓婏紝浠ユ綾繪帹銆傝繖鏍鳳紝涓や釜鏁頒腑闂村氨鍙兘闇瑕佸姞鍏ュ~鍏呭瓧鑺傦紝鎵浠ユ暣涓粨鏋勪綋鐨剆izeof鍊煎氨澧為暱浜嗐?br>璁╂垜浠氦鎹竴涓婼1涓璫har涓巌nt鐨勪綅緗細
struct S2
{
int i;
char c;
};
鐪嬬湅sizeof(S2)鐨勭粨鏋滀負澶氬皯錛屾庝箞榪樻槸8鍐嶇湅鐪嬪唴瀛橈紝鍘熸潵鎴愬憳c鍚庨潰浠嶇劧鏈?涓~鍏呭瓧鑺傦紝榪欏張鏄負浠涔堝晩鍒潃鎬ワ紝涓嬮潰鎬葷粨瑙勫緥銆?br>瀛楄妭瀵歸綈鐨勭粏鑺傚拰緙栬瘧鍣ㄥ疄鐜扮浉鍏籌紝浣嗕竴鑸岃█錛屾弧瓚充笁涓噯鍒欙細
1) 緇撴瀯浣撳彉閲忕殑棣栧湴鍧鑳藉琚叾鏈瀹藉熀鏈被鍨嬫垚鍛樼殑澶у皬鎵鏁撮櫎錛?br>2) 緇撴瀯浣撴瘡涓垚鍛樼浉瀵逛簬緇撴瀯浣撻鍦板潃鐨勫亸縐婚噺錛坥ffset錛夐兘鏄垚鍛樺ぇ灝忕殑鏁存暟鍊嶏紝濡傛湁闇瑕佺紪璇戝櫒浼氬湪鎴愬憳涔嬮棿鍔犱笂濉厖瀛楄妭錛坕nternal adding錛夛紱
3) 緇撴瀯浣撶殑鎬誨ぇ灝忎負緇撴瀯浣撴渶瀹藉熀鏈被鍨嬫垚鍛樺ぇ灝忕殑鏁存暟鍊嶏紝濡傛湁闇瑕佺紪璇戝櫒浼氬湪鏈鏈竴涓垚鍛樹箣鍚庡姞涓婂~鍏呭瓧鑺傦紙trailing padding錛夈?br>瀵逛簬涓婇潰鐨勫噯鍒欙紝鏈夊嚑鐐歸渶瑕佽鏄庯細
1) 鍓嶉潰涓嶆槸璇寸粨鏋勪綋鎴愬憳鐨勫湴鍧鏄叾澶у皬鐨勬暣鏁板嶏紝鎬庝箞鍙堣鍒板亸縐婚噺浜嗗憿鍥犱負鏈変簡絎?鐐瑰瓨鍦紝鎵浠ユ垜浠氨鍙互鍙冭檻鎴愬憳鐨勫亸縐婚噺錛岃繖鏍鋒濊冭搗鏉ョ畝鍗曘傛兂鎯充負浠涔堛?br>緇撴瀯浣撴煇涓垚鍛樼浉瀵逛簬緇撴瀯浣撻鍦板潃鐨勫亸縐婚噺鍙互閫氳繃瀹弌ffsetof()鏉ヨ幏寰楋紝榪欎釜瀹忎篃鍦╯tddef.h涓畾涔夛紝濡備笅錛?br>
渚嬪錛屾兂瑕佽幏寰桽2涓璫鐨勫亸縐婚噺錛屾柟娉曚負
size_t pos = offsetof(S2, c);// pos絳変簬4
2) 鍩烘湰綾誨瀷鏄寚鍓嶉潰鎻愬埌鐨勫儚char銆乻hort銆乮nt銆乫loat銆乨ouble榪欐牱鐨勫唴緗暟鎹被鍨嬶紝榪欓噷鎵璇寸殑“鏁版嵁瀹藉害”灝辨槸鎸囧叾sizeof鐨勫ぇ灝忋傜敱浜庣粨鏋勪綋鐨勬垚鍛樺彲浠ユ槸澶嶅悎綾誨瀷錛屾瘮濡傚彟澶栦竴涓粨鏋勪綋錛屾墍浠ュ湪瀵繪壘鏈瀹藉熀鏈被鍨嬫垚鍛樻椂錛屽簲褰撳寘鎷鍚堢被鍨嬫垚鍛樼殑瀛愭垚鍛橈紝鑰屼笉鏄妸澶嶅悎鎴愬憳鐪嬫垚鏄竴涓暣浣撱備絾鍦ㄧ‘瀹氬鍚堢被鍨嬫垚鍛樼殑鍋忕Щ浣嶇疆鏃跺垯鏄皢澶嶅悎綾誨瀷浣滀負鏁翠綋鐪嬪緟銆?br>榪欓噷鍙欒堪璧鋒潵鏈夌偣鎷楀彛錛屾濊冭搗鏉ヤ篃鏈夌偣鎸犲ご錛岃繕鏄鎴戜滑鐪嬬湅渚嬪瓙鍚э紙鍏蜂綋鏁板間粛浠C6涓轟緥錛屼互鍚庝笉鍐嶈鏄庯級錛?br>struct S3
{
char c1;
S1 s;
char c2;
};
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>sizeof( struct ) = offsetof( last item ) + sizeof( last item ) + sizeof( trailing padding )
鍒拌繖閲岋紝鏈嬪弸浠簲璇ュ緇撴瀯浣撶殑sizeof鏈変簡涓涓叏鏂扮殑璁よ瘑錛屼絾涓嶈楂樺叴寰楀お鏃╋紝鏈変竴涓獎鍝峴izeof鐨勯噸瑕佸弬閲忚繕鏈鎻愬強錛岄偅渚挎槸緙栬瘧鍣ㄧ殑pack鎸囦護銆傚畠鏄敤鏉ヨ皟鏁寸粨鏋勪綋瀵歸綈鏂瑰紡鐨勶紝涓嶅悓緙栬瘧鍣ㄥ悕縐板拰鐢ㄦ硶鐣ユ湁涓嶅悓錛孷C6涓氳繃#pragma pack瀹炵幇錛屼篃鍙互鐩存帴淇敼/Zp緙栬瘧寮鍏熾?pragma pack鐨勫熀鏈敤娉曚負錛?pragma pack( n )錛宯涓哄瓧鑺傚榻愭暟錛屽叾鍙栧間負1銆?銆?銆?銆?6錛岄粯璁ゆ槸8錛屽鏋滆繖涓兼瘮緇撴瀯浣撴垚鍛樼殑sizeof鍊煎皬錛岄偅涔?br>璇ユ垚鍛樼殑鍋忕Щ閲忓簲璇ヤ互姝ゅ間負鍑嗭紝鍗蟲槸璇達紝緇撴瀯浣撴垚鍛樼殑鍋忕Щ閲忓簲璇ュ彇浜岃呯殑鏈灝忓鹼紝
鍏紡濡備笅錛?br>offsetof( item ) = min( n, sizeof( item ) )
鍐嶇湅紺轟緥錛?br>#pragma pack(push)
#pragma pack(2) // 蹇呴』鍦ㄧ粨鏋勪綋瀹氫箟涔嬪墠浣跨敤
struct S1
{
char c;
int i;
};
struct S3
{
char c1;
S1 s;
char c2;
};
#pragma pack(pop) // 鎭㈠鍏堝墠鐨刾ack璁劇疆
璁$畻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>
鐜板湪錛屾湅鍙嬩滑鍙互杞繪澗鐨勫嚭涓鍙f皵浜嗭紝:)
榪樻湁涓鐐硅娉ㄦ剰錛?#8220;絀虹粨鏋勪綋”錛堜笉鍚暟鎹垚鍛橈級鐨勫ぇ灝忎笉涓?錛岃屾槸1銆傝瘯鎯充竴涓?#8220;涓嶅崰絀洪棿”鐨勫彉閲忓浣曡鍙栧湴鍧銆佷袱涓笉鍚岀殑“絀虹粨鏋勪綋”鍙橀噺鍙堝浣曞緱浠ュ尯鍒嗗憿浜庢槸錛?#8220;絀虹粨鏋勪綋”鍙橀噺涔熷緱琚瓨鍌紝榪欐牱緙栬瘧鍣ㄤ篃灝卞彧鑳戒負鍏跺垎閰嶄竴涓瓧鑺傜殑絀洪棿鐢ㄤ簬鍗犱綅浜嗐傚涓嬶細
struct S5 { };
sizeof( S5 ); // 緇撴灉涓?
8. 鍚綅鍩熺粨鏋勪綋鐨剆izeof
鍓嶉潰宸茬粡璇磋繃錛屼綅鍩熸垚鍛樹笉鑳藉崟鐙鍙杝izeof鍊鹼紝鎴戜滑榪欓噷瑕佽璁虹殑鏄惈鏈変綅鍩熺殑緇撴瀯浣撶殑sizeof錛屽彧鏄冭檻鍒板叾鐗規畩鎬ц屽皢鍏朵笓闂ㄥ垪浜嗗嚭鏉ャ?br>C99瑙勫畾int銆乽nsigned int鍜宐ool鍙互浣滀負浣嶅煙綾誨瀷錛屼絾緙栬瘧鍣ㄥ嚑涔庨兘瀵規浣滀簡鎵╁睍錛屽厑璁稿叾瀹冪被鍨嬬被鍨嬬殑瀛樺湪銆備嬌鐢ㄤ綅鍩熺殑涓昏鐩殑鏄帇緙╁瓨鍌紝鍏跺ぇ鑷磋鍒欎負錛?br>1) 濡傛灉鐩擱偦浣嶅煙瀛楁鐨勭被鍨嬬浉鍚岋紝涓斿叾浣嶅涔嬪拰灝忎簬綾誨瀷鐨剆izeof澶у皬錛屽垯鍚庨潰鐨勫瓧孌靛皢绱ч偦鍓嶄竴涓瓧孌靛瓨鍌紝鐩村埌涓嶈兘瀹圭撼涓烘錛?br>2) 濡傛灉鐩擱偦浣嶅煙瀛楁鐨勭被鍨嬬浉鍚岋紝浣嗗叾浣嶅涔嬪拰澶т簬綾誨瀷鐨剆izeof澶у皬錛屽垯鍚庨潰鐨勫瓧孌靛皢浠庢柊鐨勫瓨鍌ㄥ崟鍏冨紑濮嬶紝鍏跺亸縐婚噺涓哄叾綾誨瀷澶у皬鐨勬暣鏁板嶏紱
3) 濡傛灉鐩擱偦鐨勪綅鍩熷瓧孌電殑綾誨瀷涓嶅悓錛屽垯鍚勭紪璇戝櫒鐨勫叿浣撳疄鐜版湁宸紓錛孷C6閲囧彇涓嶅帇緙╂柟寮忥紝Dev-C++閲囧彇鍘嬬緝鏂瑰紡錛?br>4) 濡傛灉浣嶅煙瀛楁涔嬮棿絀挎彃鐫闈炰綅鍩熷瓧孌碉紝鍒欎笉榪涜鍘嬬緝錛?br>5) 鏁翠釜緇撴瀯浣撶殑鎬誨ぇ灝忎負鏈瀹藉熀鏈被鍨嬫垚鍛樺ぇ灝忕殑鏁存暟鍊嶃?br>榪樻槸璁╂垜浠潵鐪嬬湅渚嬪瓙銆?br>紺轟緥1錛?br>struct BF1
{
char f1 : 3;
char f2 : 4;
char f3 : 5;
};
鍏跺唴瀛樺竷灞涓猴細
|_f1__|__f2__|_|____f3___|____|
|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|
0 3 7 8 1316
浣嶅煙綾誨瀷涓篶har錛岀1涓瓧鑺備粎鑳藉綰充笅f1鍜宖2錛屾墍浠2琚帇緙╁埌絎?涓瓧鑺備腑錛岃宖3鍙?br>鑳戒粠涓嬩竴涓瓧鑺傚紑濮嬨傚洜姝izeof(BF1)鐨勭粨鏋滀負2銆?br>紺轟緥2錛?br>struct BF2
{
char f1 : 3;
short f2 : 4;
char f3 : 5;
};
鐢變簬鐩擱偦浣嶅煙綾誨瀷涓嶅悓錛屽湪VC6涓叾sizeof涓?錛屽湪Dev-C++涓負2銆?br>紺轟緥3錛?br>struct BF3
{
char f1 : 3;
char f2;
char f3 : 5;
};
闈炰綅鍩熷瓧孌電┛鎻掑湪鍏朵腑錛屼笉浼氫駭鐢熷帇緙╋紝鍦╒C6鍜孌ev-C++涓緱鍒扮殑澶у皬鍧囦負3銆?br>9. 鑱斿悎浣撶殑sizeof
緇撴瀯浣撳湪鍐呭瓨緇勭粐涓婃槸欏哄簭寮忕殑錛岃仈鍚堜綋鍒欐槸閲嶅彔寮忥紝鍚勬垚鍛樺叡浜竴孌靛唴瀛橈紝鎵浠ユ暣涓仈鍚堜綋鐨剆izeof涔熷氨鏄瘡涓垚鍛榮izeof鐨勬渶澶у箋傜粨鏋勪綋鐨勬垚鍛樹篃鍙互鏄鍚堢被鍨嬶紝榪欓噷錛屽鍚堢被鍨嬫垚鍛樻槸琚綔涓烘暣浣撹冭檻鐨勩?br>鎵浠ワ紝涓嬮潰渚嬪瓙涓紝U鐨剆izeof鍊肩瓑浜巗izeof(s)銆?br>union U
{
int i;
char c;
S1 s;
};
杞嚜錛?a >http://blog.sina.com.cn/s/blog_5af743940100ctd9.html
]]>
#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;
}
]]>
#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;
}
]]>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
using namespace std;
template<class T> void Max_Heap(T a[],int i,int size)

{
int r = 2*i + 2;
int l = 2*i + 1;
int largest;
if (l<size && a[l]>=a[i])
{
largest = l;
}
else
largest = i;
if (r<size && a[r] >=a[largest])
{
largest = r;
}
if (largest != i)
{
swap(a[largest],a[i]);
Max_Heap(a,largest,size);
}
}
template<class T> void Build_Max_Heap(T a[],int size)

{
for (int i=size/2;i>=0;i--)
{
Max_Heap(a,i,size);
}
}
template<class T> void HeapSort(T a[],int size)

{
Build_Max_Heap(a,size);
for (int i=size-1;i>=1;i--)
{
swap(a[i],a[0]); //灝嗘渶澶ф暟鎹㈠埌鏁扮粍鏈熬
//show(a,size);
size--;
Max_Heap(a,0,size);
}
}
template<class T> void show(T a[],int size)

{
cout<<"鎺掑簭鍚庣粨鏋滀負"<<endl;
for (int i=0;i<size;i++)
{
cout<<a[i]<<endl;
}
}
int main()

{
int num;
cin>>num;
char* input = new char[num];
for (int i=0;i<num;i++)
{
cin>>input[i];
}
// Build_Max_Heap(input,num); //寤虹珛鏈澶у爢
HeapSort(input,num); //鍫嗘帓搴?/span>
show(input,num);
}
]]>
銆銆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>
銆銆DataSize= DataSizePerLine* biHeight銆?
銆銆涓婅堪鏄疊MP鏂囦歡鏍煎紡鐨勮鏄庯紝鎼炴竻妤氫簡浠ヤ笂鐨勭粨鏋勶紝灝卞彲浠ユ紜殑鎿嶄綔鍥懼儚鏂囦歡錛屽瀹冭繘琛岃鎴栧啓鎿嶄綔浜嗐?br>
杞嚜http://hi.baidu.com/kennlee/blog/item/52375eca63394743f31fe7d8.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, 0, sizeof (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;
}
]]>
#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);
}

]]>