??xml version="1.0" encoding="utf-8" standalone="yes"?>久久精品人人做人人爽电影蜜月 ,亚洲国产精品综合久久网络,国内精品久久久久影院亚洲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创徏一个二叉树(wi)Q下?wbr>是几个常用函数的使用Ҏ(gu)和代表的意?br>#include
#include
#include
#include
using namespace std;

Q?Q创Z个数l,q添加数?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);

Q?Qmake_heapQv_Arry.beginQ), v_Arry.endQ), less()) //建堆Q其实就是徏二叉?wi)?根节Ҏ(gu)最大|其每一个节炚w于或等于其父节点;使用greater()则相反,根节Ҏ(gu)最|其每一个节?wbr>都大于或{于其父节点

Q?Q此时可以输出查看一下徏好的堆是不是一个标准的二叉?br>我的输出l果是:(x)55Q?0Q?Q?Q?Q?wbr>3Q?Q?Q?Q?Q?wbr>2
变成二叉?wi)就是如下?x)
<!--[if !vml]--><!--[endif]--> <!--[if !vml]--><!--[endif]-->

 

l果不是唯一单一定要满父节点和子节点的大小关系?br>Q?Qpop_heap(v_Arry.begin(), v_Arry.end());//把根节点Ud末尾Qƈ没有删除
     v_Arry.pop_back();//删除该节?br>    此时输出l果Q?0Q?wbr>9Q?Q?Q?Q?Q?wbr>4Q?Q?Q?
二叉?wi)如下?x)

 

Q?Qv_Arry.push_back(55); //只是d数据攑ֈ子节?br>    push_heap(v_Arry.begin(), v_Arry.end());//往二叉?wbr>中插入数据,满子节点小于等于父节点
此时输出l果Q?5Q?wbr>10Q?Q?Q?Q?Q?Q?Q?Q?Q?
二叉?wi)如下?x)

 

Q?Qsort_heap(v_Arry.begin(), v_Arry.end());//对二叉树(wi)所有节点进行排?br>此时输出l果Q?Q?Q?Q?Q?Q?Q?Q?Q?Q?0Q?5

Q?Qfind ( v_Arry.begin(), v_Arry.end()Q?value );// 从begin到end查找valueQ若?wbr>不到Q返回end

原文地址Q?a >http://blog.zol.com.cn/1356/article_1355249.html


hunter 2010-05-29 07:37 发表评论
]]>
q用计数排序q行基数排序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重复Ҏ(gu)有的d位数字都q行排序Q仅需要d遍就可以一堆卡片进行排序?br>q里又运用了基数排序的方法,所以ȝ旉复杂度ؓ(f)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数组
    {
        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
<<"输入个数?qing)位?/span>"<<endl;
    cin
>>num>>d;
    
int* a = new int[num];
    
int* b = new int[num];
    cout
<<"排序前:(x)"<<endl;
    
for(int i=0;i<num;i++)
    
{
        cin
>>a[i];
    }

        
    RadixSort(a,b,d,num);

    cout
<<"排序后:(x)"<<endl;
    
for (int j=0;j<num;j++)
    
{
        cout
<<b[j]<<endl;
    }


    delete [] a;
    delete [] b;
}



hunter 2010-03-11 11:08 发表评论
]]>
sizeof用法Q{Q?/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="qygmq44" class=Apple-converted-space> </span> <wbr> <wbr><span id="4yu4wea" class=Apple-converted-space> </span>sizeof(cd说明W,数组名或表达?;<br>?br> <wbr> <wbr><span id="e4eiak6" class=Apple-converted-space> </span> <wbr> <wbr><span id="uoum28o" class=Apple-converted-space> </span>sizeof 变量?br><br>1. 定义Q?br>sizeof是C/C++中的一个操作符QoperatorQ是也,单的说其作用是q回一个对象或者类型所占的内存字节数?br>MSDN上的解释为:(x)<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>其返回值类型ؓ(f)size_tQ在头文件stddef.h中定义。这是一个依赖于~译pȝ的|一般定义ؓ(f)<br>typedef unsigned int size_t;<br>世上~译器林林L,但作Z个规范,它们都会(x)保证char、signed char和unsigned<br>char的sizeofgؓ(f)1Q毕竟char是我们编E能用的最数据类型?br>2. 语法Q?br>sizeof有三U语法Ş式,如下Q?br>1) sizeof( object ); // sizeof( 对象 );<br>2) sizeof( type_name ); // sizeof( cd );<br>3) sizeof object; // sizeof 对象;<br>所以,<br>int i;<br>sizeof( i ); <wbr><span id="qauu0qw" class=Apple-converted-space> </span>// ok<br>sizeof i; <wbr> <wbr> <wbr> <wbr><span id="oasmwek" class=Apple-converted-space> </span>// ok<br>sizeof( int ); // ok<br>sizeof int; <wbr> <wbr> <wbr><span id="w4g44iq" class=Apple-converted-space> </span>// error<br>既然写法3可以用写?代替Qؓ(f)求Ş式统一以及(qing)减少我们大脑的负担,W?U写法,忘掉它吧Q实际上Qsizeof计算对象的大也是{换成对对象类型的计算Q也是_(d)同种cd的不同对象其sizeof值都是一致的。这里,对象可以q一步g伸至表达式,即sizeof可以对一个表辑ּ求|~译器根据表辑ּ的最l结果类型来定大小Q一般不?x)对表达式进行计。如Q?br>sizeof( 2 ); <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr>// 2的类型ؓ(f)intQ所以等价于 sizeof( int );<br>sizeof( 2 + 3.14 ); <wbr> <wbr><span id="ceygqki" class=Apple-converted-space> </span>// 3.14的类型ؓ(f)doubleQ?也会(x)被提升成doublecdQ所以等价于 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">也可以对一个函数调用求|其结果是函数q回cd的大,函数q不?x)被调用Q我们来看一个完整的例子Q?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() 的返回值类型ؓ(f)charQ所以sz = sizeof(char )Qfoo()q不?x)被调?br>printf("sizeof( foo() ) = %d\n", sz);<br>}<br>C99标准规定Q函数、不能确定类型的表达式以?qing)位域(bit-fieldQ成员不能被计算sizeof|即下面这些写法都是错误的Q?br>sizeof( foo );// error<br>void foo2() { }<br>sizeof( foo2() );// error<br>struct S<br>{<br> <wbr> <wbr><span id="scgyu4m" class=Apple-converted-space> </span> <wbr> <wbr> <wbr><span id="4mscuyy" class=Apple-converted-space> </span>unsigned int f1 : 1;<br> <wbr> <wbr><span id="uu64euu" class=Apple-converted-space> </span> <wbr> <wbr> <wbr><span id="owyauoo" class=Apple-converted-space> </span>unsigned int f2 : 5;<br> <wbr> <wbr><span id="284ie4k" class=Apple-converted-space> </span> <wbr> <wbr> <wbr><span id="24okueg" class=Apple-converted-space> </span>unsigned int f3 : 12;<br>};<br>sizeof( S.f1 );// error<br>3. sizeof的常量?br>sizeof的计发生在~译时刻Q所以它可以被当作常量表辑ּ使用Q如Q?br>char ary[ sizeof( int ) * 10 ]; // ok<br>最新的C99标准规定sizeof也可以在q行时刻q行计算Q如下面的程序在Dev-C++中可以正执行:(x)<br>int n;<br>n = 10; // n动态赋?br>char ary[n]; // C99也支持数l的动态定?br>printf("%d\n", sizeof(ary)); // ok. 输出10<br>但在没有完全实现C99标准的编译器中就行不通了Q上面的代码在VC6中就通不q编译。所以我们最好还是认为sizeof是在~译期执行的Q这样不?x)带来错误,让程序的可移植性强些?br>4. 基本数据cd的sizeof<br>q里的基本数据类型指short、int、long、float、doubleq样的简单内|数据类型,׃它们都是和系l相关的Q所以在不同的系l下取值可能不同,q务必引h们的注意Q尽量不要在q方面给自己E序的移植造成ȝ?br>一般的Q在32位编译环境中Qsizeof(int)的取gؓ(f)4?br>5. 指针变量的sizeof<br>学过数据l构的你应该知道指针是一个很重要的概念,它记录了另一个对象的地址。既然是来存攑֜址的,那么它当然等于计机内部地址ȝ的宽度。所以在32位计机中,一个指针变量的q回值必定是4Q注意结果是以字节ؓ(f)单位Q,可以预计Q在来?4位系l中指针变量的sizeofl果??br>char* pc = "abc";<br>int* pi;<br>string* ps;<br>char** ppc = &pc;<br>void (*pf)();// 函数指针<br>sizeof( pc ); // l果?<br>sizeof( pi ); // l果?<br>sizeof( ps ); // l果?<br>sizeof( ppc ); // l果?<br>sizeof( pf );// l果?<br>指针变量的sizeofg指针所指的对象没有M关系Q正是由于所有的指针变量所占内存大相{,所以MFC消息处理函数使用两个参数WPARAM、LPARAMp传递各U复杂的消息l构Q用指向结构体的指针)?br>6. 数组的sizeof<br>数组的sizeof值等于数l所占用的内存字节数Q如Q?br>char a1[] = "abc";<br>int a2[3];<br>sizeof( a1 ); // l果?Q字W?末尾q存在一个NULLl止W?br>sizeof( a2 ); // l果?*4=12Q依赖于intQ?br>一些朋友刚开始时把sizeof当作了求数组元素的个敎ͼ现在Q你应该知道q是不对的,那么应该怎么求数l元素的个数呢EasyQ通常有下面两U写法:(x)<br>int c1 = sizeof( a1 ) / sizeof( char ); // 总长?单个元素的长?br>int c2 = sizeof( a1 ) / sizeof( a1[0] ); // 总长?W一个元素的长度<br>写到q里Q提一问,下面的c3Qc4值应该是多少?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的值时已经意识到c3{错了,是的Qc3!=3。这里函数参数a3已不再是数组cdQ而是蜕变成指针,相当于char* a3Qؓ(f)什么仔l想惛_不难明白Q我们调用函数foo1ӞE序?x)在栈上分配一个大ؓ(f)3的数l吗不会(x)Q数l是“传址”的,调用者只需实参的地址传递过去,所以a3自然为指针类型(char*Q,c3的g׃ؓ(f)4?br>7. l构体的sizeof<br>q是初学者问得最多的一个问题,所以这里有必要多费点笔墨。让我们先看一个结构体Q?br>struct S1<br>{<br>char c;<br>int i;<br>};<br>问sizeof(s1){于多少聪明的你开始思考了Qchar?个字节,int?个字节,那么加v来就应该?。是q样吗你在你机器上试q了吗也怽是对的,但很可能你是错的QVC6中按默认讄得到的结果ؓ(f)8?br>WhyZ么受伤的L?br>请不要沮丧,我们来好好琢一下sizeof的定义——sizeof的结果等于对象或者类型所占的内存字节敎ͼ好吧Q那p我们来看看S1的内存分配情况:(x)<br>S1 s1 = { 'a', 0xFFFFFFFF };<br>定义上面的变量后Q加上断点,q行E序Q观察s1所在的内存Q你发现了什?br>以我的VC6.0ZQs1的地址?x0012FF78Q其数据内容如下Q?br>0012FF78: 61 CC CC CC FF FF FF FF<br>发现了什么怎么中间Ҏ(gu)?个字节的CC看看MSDN上的说明Q?br>When applied to a structure type or variable, sizeof returns the actual size, which may include padding bytes inserted for alignment.<br>原来如此Q这是传说中的字节寚w啊!一个重要的话题出现了?br>Z么需要字节对齐计机l成原理教导我们q样有助于加快计机的取数速度Q否则就得多花指令周期了。ؓ(f)此,~译器默认会(x)对结构体q行处理Q实际上其它地方的数据变量也是如此)Q让宽度?的基本数据类型(short{)都位于能?整除的地址上,让宽度ؓ(f)4的基本数据类型(int{)都位于能?整除的地址上,以此cL。这P两个C间就可能需要加入填充字节,所以整个结构体的sizeof值就增长了?br>让我们交换一下S1中char与int的位|:(x)<br>struct S2<br>{<br>int i;<br>char c;<br>};<br>看看sizeof(S2)的结果ؓ(f)多少Q怎么q是8再看看内存,原来成员c后面仍然?个填充字节,q又是ؓ(f)什么啊别着急,下面ȝ规律?br>字节寚w的细节和~译器实现相养I但一般而言Q满三个准则:(x)<br>1) l构体变量的首地址能够被其最宽基本类型成员的大小所整除Q?br>2) l构体每个成员相对于l构体首地址的偏U量QoffsetQ都是成员大的整数倍,如有需要编译器?x)在成员之间加上填充字节Qinternal addingQ;<br>3) l构体的dؓ(f)l构体最宽基本类型成员大的整数倍,如有需要编译器?x)在最末一个成员之后加上填充字节(trailing paddingQ?br>对于上面的准则,有几炚w要说明:(x)<br>1) 前面不是说结构体成员的地址是其大小的整数倍,怎么又说到偏U量了呢因ؓ(f)有了W?点存在,所以我们就可以只考虑成员的偏U量Q这h考v来简单。想想ؓ(f)什么?br>l构体某个成员相对于l构体首地址的偏U量可以通过宏offsetof()来获得,q个宏也在stddef.h中定义,如下Q?br> <wbr> <wbr><span id="wak28aa" class=Apple-converted-space> </span>#define offsetof(s,m) (size_t)&(((s *)0)->m)<br>例如Q想要获得S2中c的偏U量Q方法ؓ(f)<br>size_t pos = offsetof(S2, c);// pos{于4<br>2) 基本cd是指前面提到的像char、short、int、float、doubleq样的内|数据类型,q里所说的“数据宽度”是指其sizeof的大。由于结构体的成员可以是复合cdQ比如另外一个结构体Q所以在L最宽基本类型成员时Q应当包括复合类型成员的子成员,而不是把复合成员看成是一个整体。但在确定复合类型成员的偏移位置时则是将复合cd作ؓ(f)整体看待?br>q里叙述h有点拗口Q思考v来也有点挠头Q还是让我们看看例子吧(具体数g以VC6ZQ以后不再说明)Q?br>struct S3<br>{<br>char c1;<br>S1 s;<br>char c2;<br>};<br>S1的最宽简单成员的cd为intQS3在考虑最宽简单类型成员时是将S1“打散”看的Q所以S3的最宽简单类型ؓ(f)intQ这P通过S3定义的变量,其存储空间首地址需要被4整除Q整个sizeof(S3)的g应该?整除?br>c1的偏U量?Qs的偏U量呢这时s是一个整体,它作为结构体变量也满_面三个准则,所以其大小?Q偏U量?Qc1与s之间侉K?个填充字节,而c2与s之间׃需要了Q所以c2的偏U量?2Q算上c2的大ؓ(f)13Q?3是不能被4整除的,q样末尾q得补上3个填充字节。最后得到sizeof(S3)的gؓ(f)16?br>通过上面的叙qͼ我们可以得到一个公式:(x)<br>l构体的大小{于最后一个成员的偏移量加上其大小再加上末填充字节数目Q即Q?br>sizeof( struct ) = offsetof( last item ) + sizeof( last item ) + sizeof( trailing padding )<br>到这里,朋友们应该对l构体的sizeof有了一个全新的认识Q但不要高兴得太早,有一个媄响sizeof的重要参量还未被提及(qing)Q那便是~译器的pack指o(h)。它是用来调整结构体寚w方式的,不同~译器名U和用法略有不同QVC6中通过#pragma pack实现Q也可以直接修改/Zp~译开兟?pragma pack的基本用法ؓ(f)Q?pragma pack( n )Qn为字节对齐数Q其取gؓ(f)1????6Q默认是8Q如果这个值比l构体成员的sizeof值小Q那?br>该成员的偏移量应该以此gؓ(f)准,x_(d)l构体成员的偏移量应该取二者的最|<br>公式如下Q?br>offsetof( item ) = min( n, sizeof( item ) )<br>再看CZQ?br>#pragma pack(push) <wbr> <wbr><span id="ywa4suc" class=Apple-converted-space> </span>// 当前pack讄压栈保存<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) // 恢复先前的pack讄<br>计算sizeof(S1)Ӟmin(2, sizeof(i))的gؓ(f)2Q所以i的偏U量?Q加上sizeof(i){于6Q能够被2整除Q所以整个S1的大ؓ(f)6?br>同样Q对于sizeof(S3)Qs的偏U量?Qc2的偏U量?Q加上sizeof(c2){于9Q不能被2整除Q添加一个填充字节,所以sizeof(S3){于10?br><br>现在Q朋友们可以L的出一口气了,:)<br>q有一点要注意Q?#8220;I结构体”Q不含数据成员)的大不?Q而是1。试想一?#8220;不占I间”的变量如何被取地址、两个不同的“I结构体”变量又如何得以区分呢于是Q?#8220;I结构体”变量也得被存储,q样~译器也只能ؓ(f)其分配一个字节的I间用于占位了。如下:(x)<br>struct S5 { };<br>sizeof( S5 ); // l果?<br>8. 含位域结构体的sizeof<br>前面已经说过Q位域成员不能单独被取sizeof|我们q里要讨论的是含有位域的l构体的sizeofQ只是考虑到其Ҏ(gu)性而将其专门列了出来?br>C99规定int、unsigned int和bool可以作ؓ(f)位域cdQ但~译器几乎都Ҏ(gu)作了扩展Q允许其它类型类型的存在。用位域的主要目的是压~存储,其大致规则ؓ(f)Q?br>1) 如果盔R位域字段的类型相同,且其位宽之和于cd的sizeof大小Q则后面的字D将紧邻前一个字D存储,直到不能容纳为止Q?br>2) 如果盔R位域字段的类型相同,但其位宽之和大于cd的sizeof大小Q则后面的字D将从新的存储单元开始,其偏U量为其cd大小的整数倍;<br>3) 如果盔R的位域字D늚cd不同Q则各编译器的具体实现有差异QVC6采取不压~方式,Dev-C++采取压羃方式Q?br>4) 如果位域字段之间I插着非位域字D,则不q行压羃Q?br>5) 整个l构体的dؓ(f)最宽基本类型成员大的整数倍?br>q是让我们来看看例子?br>CZ1Q?br>struct BF1<br>{<br>char f1 : 3;<br>char f2 : 4;<br>char f3 : 5;<br>};<br>其内存布局为:(x)<br>|_f1__|__f2__|_|____f3___|____|<br>|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|<br>0 3 7 8 1316<br>位域cd为charQ第1个字节仅能容U下f1和f2Q所以f2被压~到W?个字节中Q而f3?br>能从下一个字节开始。因此sizeof(BF1)的结果ؓ(f)2?br>CZ2Q?br>struct BF2<br>{<br>char f1 : 3;<br>short f2 : 4;<br>char f3 : 5;<br>};<br>׃盔R位域cd不同Q在VC6中其sizeof?Q在Dev-C++中ؓ(f)2?br>CZ3Q?br>struct BF3<br>{<br>char f1 : 3;<br>char f2;<br>char f3 : 5;<br>};<br>非位域字D늩插在其中Q不?x)生压~,在VC6和Dev-C++中得到的大小均ؓ(f)3?br>9. 联合体的sizeof<br>l构体在内存l织上是序式的Q联合体则是重叠式,各成员共享一D内存,所以整个联合体的sizeof也就是每个成员sizeof的最大倹{结构体的成员也可以是复合类型,q里Q复合类型成员是被作为整体考虑的?br>所以,下面例子中,U的sizeof值等于sizeof(s)?br>union U<br>{<br>int i;<br>char c;<br>S1 s;<br>};<br><br><br>转自Q?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计数排序的基本思想是Ҏ(gu)一个输入元素XQ确定出于X的元素个数?br>有了q一信息可以把X直接攑ֈ它在最l输出数l中的位|上?br>例如Q如果有17个元素小于XQ则X属于第18个输Z|?br>在计数排序算法的代码中,我们假定输入是个数组A[0...n-1]Qlength[A]=n。另外还需要两个数l:(x)存放排序l果的B[0...n-1]Q以?qing)提供?f)时存储区的C[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
<<"输入最大整数及(qing)输入个数"<<endl;
    cin
>>max;
    cin
>>num;
    
int* a = new int[num];
    
int* b = new int[num];
    cout
<<"排序前:(x)"<<endl;
    
for(int i=0;i<num;i++)
    
{
        cin
>>a[i];
        
if (a[i]>max)
            i
--;
    }

        
    CountSort(a,b,max,num);

    cout
<<"排序后:(x)"<<endl;
    
for (int j=0;j<num;j++)
    
{
        cout
<<b[j]<<endl;
    }


    delete [] a;
    delete [] b;
}



hunter 2010-03-10 23:29 发表评论
]]>
快速排序及(qing)二分查找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)               //于卫兵的D行对?/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
<<"排序前:(x)"<<endl;
    
for(int i=0;i<num;i++)
        cin
>>a[i];
    QuickSort(a,
0,num-1);
    cout
<<"排序后:(x)"<<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">排序后结果ؓ(f)</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文gl构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文g由文件头、位图信息头、颜色信息和囑Ş数据四部分组成。文件头主要包含文g的大、文件类型、图像数据偏L件头的长度等信息Q位图信息头包含图象的尺怿息、图像用几个比特数值来表示一个像素、图像是否压~、图像所用的颜色数等信息。颜色信息包含图像所用到的颜色表Q显C图像时需用到q个颜色表来生成调色板,但如果图像ؓ(f)真彩Ԍ既图像的每个像素?4个比Ҏ(gu)表示Q文件中没有这一块信息,也就不需要操作调色板。文件中的数据块表示囑փ的相应的像素|需要注意的是:(x)囑փ的像素值在文g中的存放序Z左到叻I从下CQ也是_(d)在BMP文g中首先存攄是图像的最后一行像素,最后才存储囑փ的第一行像素,但对与同一行的像素Q则是按照先左边后右边的的顺序存储的Q另外一个需要读者朋友关注的l节是:(x)文g存储囑փ的每一行像素值时Q如果存储该行像素值所占的字节Cؓ(f)4的倍数Q则正常存储Q否则,需要在后端?Q凑?的倍数?

  2. BMP文g?

  BMP文g头数据结构含有BMP文g的类型、文件大和位图起始位置{信息。其l构定义如下:

typedef struct tagBITMAPFILEHEADER
{
WORD bfType; // 位图文g的类型,必须?#8220;BM”
DWORD bfSize; // 位图文g的大,以字节ؓ(f)单位
WORD bfReserved1; // 位图文g保留字,必须?
WORD bfReserved2; // 位图文g保留字,必须?
DWORD bfOffBits; // 位图数据的v始位|,以相对于位图文g头的偏移量表C,以字节ؓ(f)单位
} BITMAPFILEHEADERQ该l构占据14个字节?

  3. 位图信息?

  BMP位图信息头数据用于说明位囄寸{信息。其l构如下Q?br>
typedef struct tagBITMAPINFOHEADER{
DWORD biSize; // 本结构所占用字节?br>LONG biWidth; // 位图的宽度,以像素ؓ(f)单位
LONG biHeight; // 位图的高度,以像素ؓ(f)单位
WORD biPlanes; // 目标讑֤的^面数不清Q必Mؓ(f)1
WORD biBitCount// 每个像素所需的位敎ͼ必须?(双色), 4(16?Q?(256??4(真彩?之一
DWORD biCompression; // 位图压羃cdQ必L 0(不压~?,1(BI_RLE8压羃cd)?(BI_RLE4压羃cd)之一
DWORD biSizeImage; // 位图的大,以字节ؓ(f)单位
LONG biXPelsPerMeter; // 位图水^分L率,每米像素?br>LONG biYPelsPerMeter; // 位图垂直分L率,每米像素?br>DWORD biClrUsed;// 位图实际使用的颜色表中的颜色?br>DWORD biClrImportant;// 位图昄q程中重要的颜色?br>} BITMAPINFOHEADERQ该l构占据40个字节?

  注意Q对于BMP文g格式Q在处理单色囑փ和真彩色囑փ的时候,无论图象数据多么庞大Q都不对图象数据q行M压羃处理Q一般情况下Q如果位N用压~格式,那么16色图像采用RLE4压羃法Q?56色图像采用RLE8压羃法?br>
  4. 颜色?

  颜色表用于说明位图中的颜Ԍ它有若干个表,每一个表Ҏ(gu)一个RGBQUADcd的结构,定义一U颜艌ӀRGBQUADl构的定义如?

typedef struct tagRGBQUAD {
BYTErgbBlue;// 蓝色的亮?D围ؓ(f)0-255)
BYTErgbGreen; // l色的亮?D围ؓ(f)0-255)
BYTErgbRed; // U色的亮?D围ؓ(f)0-255)
BYTErgbReserved;// 保留Q必Mؓ(f)0
} RGBQUAD;

  颜色表中RGBQUADl构数据的个数由BITMAPINFOHEADER 中的biBitCountҎ(gu)定Q当biBitCount=1,4,8Ӟ分别?,16,256个颜色表,当biBitCount=24Ӟ囑փ为真彩色Q图像中每个像素的颜色用三个字节表示Q分别对应R、G、B|囑փ文g没有颜色表项。位图信息头和颜色表l成位图信息QBITMAPINFOl构定义如下:

typedef struct tagBITMAPINFO {
BITMAPINFOHEADER bmiHeader; // 位图信息?br>RGBQUAD bmiColors[1]; // 颜色?br>} BITMAPINFO;

  注意QRGBQUAD数据l构中,增加了一个保留字DrgbReservedQ它不代表Q何颜Ԍ必须取固定的gؓ(f)“0”Q同ӞRGBQUADl构中定义的颜色gQ红艌Ӏ绿色和蓝色的排列顺序与一般真彩色囑փ文g的颜色数据排列顺序恰好相反,既:(x)若某个位图中的一个像素点的颜色的描述?#8220;00Q?0QffQ?0”Q则表示该点为红Ԍ而不是蓝艌Ӏ?br>
  5. 位图数据

  位图数据记录了位囄每一个像素值或该对应像素的颜色表的索引|囑փ记录序是在扫描行内是从左到?扫描行之间是从下C。这U格式我们又UCؓ(f)Bottom_Up位图Q当然与之相对的q有Up_Down形式的位图,它的记录序是从上到下的Q对于这UŞ式的位图Q也不存在压~Ş式。位囄一个像素值所占的字节敎ͼ(x)当biBitCount=1Ӟ8个像素占1个字节;当biBitCount=4Ӟ2个像素占1个字节;当biBitCount=8Ӟ1个像素占1个字节;当biBitCount=24?1个像素占3个字节,此时囑փ为真彩色囑փ。当囑փ不是为真彩色Ӟ囑փ文g中包含颜色表Q位囄数据表示对应像素点在颜色表中相应的烦引|当ؓ(f)真彩色时Q每一个像素用三个字节表示囑փ相应像素点彩色|每个字节分别对应R、G、B分量的|q时候图像文件中没有颜色表。上面我已经讲过了,Windows规定囑փ文g中一个扫描行所占的字节数必L4的倍数(即以字ؓ(f)单位),不的以0填充Q图像文件中一个扫描行所占的字节数计方法:(x)

       DataSizePerLine= (biWidth* biBitCount+31)/8Q?/ 一个扫描行所占的字节?

或?br>          DataSizePerLine= (biWidth* biBitCount+31)/32 * 4Q?/ 一个扫描行所占的字节?/strong>

(如果biBitCount == 8 ?4)

         DataSizePerLine= (biWidth* 3+3)/4*4Q?/ 一个扫描行所占的字节?

?/p>

       DataSizePerLine= (biWidth*1+3)/4*4Q?/ 一个扫描行所占的字节?
  位图数据的大按下式计算(不压~情况下)Q?br>
  DataSize= DataSizePerLine* biHeight?

  上述是BMP文g格式的说明,搞清楚了以上的结构,可以正的操作囑փ文gQ对它进行读或写操作了?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 大数盔Rhttp://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
下面是某大大的代码,思\是??中找被N整除的数Q然后打印出最的l合

大数盔R一D很值得学习(fn)Q?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++){       //大数盔R
        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 发表评论
]]>
Ʒþþþþ| þþƷһ| þþƷ99þþ㽶| þҹ³˿Ƭϼ | ˾þô߽AV| ƷþþþþþþѼ| þǿdŮվ| ƷþþþjkƷ| þܳ| Ʒþþþav| Ļ뾫ƷԴþ| þ޾ƷĻ| 97þþþ޾Ʒר| 99þþƷձһ| ƷɫۺϾþ| AVþþþò| ˾Ʒþһav| þþùҺ| ƷۺϾþĻ| þ99Ʒ鶹լլ| ޹ƷۺϾþ| þþƷԴվ| ھƷ˾þþþӰԺ԰| ɫþþۺ| þþƷav鶹ѿ| re99þ6Ʒ| ޹Ʒһþ| vaþþþ| þۺϾþùɫ| ۺպþóAV| պƷþһ| պƷþþþþ| þþƷһպAV| þþƷоƷ| ŷԴƬxxxxxþþ| þ۲ӰԺѿҹɫ| þþƷƷƾ| ˾þô߽avһ| ľþۺĻ| ҹƷþӰԺ| þۺϾþ|