ÉèΪÊ×Ò³ ¼ÓÈëÊÕ²Ø

TOP

дһ¶Î³ÌÐò£¬ÕÒ³öÊý×éÖеÚk´óСµÄÊý£¬Êä³öÊýËùÔÚµÄλÖá£
2014-11-24 01:43:25 ¡¾´ó ÖРС¡¿ ä¯ÀÀ:359´Î
Tags£º³ÌÐò ÕÒ³ö ´óС Êä³ö ËùÔÚ Î»ÖÃ

ÀýÈç{2£¬4£¬3£¬4£¬7}ÖУ¬µÚÒ»´óµÄÊýÊÇ7£¬Î»ÖÃÔÚ4¡£µÚ¶þ´ó¡¢µÚÈý´óµÄÊý¶¼ÊÇ4£¬Î»ÖÃÔÚ1¡¢3Ëæ±ãÊä³öÄÄÒ»¸ö¾ù¿É¡£º¯Êý½Ó¿ÚΪ£ºint find_orderk(const int* narry,const int n,const int k)
ÒªÇóËã·¨¸´ÔӶȲ»ÄÜÊÇO(n^2£©
//¿ìËÙÅÅÐò
#include
usingnamespacestd;
intPartition (int*L,intlow,int high)
{
inttemp = L[low];
intpt = L[low];
while (low < high)
{
while (low < high && L[high] >= pt)
¨Chigh;
L[low] = L[high];
while (low < high && L[low] <= pt)
++low;
L[low] = temp;
}
L[low] = temp;
returnlow;
}
voidQSort (int*L,intlow,int high)
{
if (low < high)
{
intpl = Partition (L,low,high);
QSort (L,low,pl - 1);
QSort (L,pl + 1,high);
}
}
intmain ()
{
intnarry[100],addr[100];
intsum = 1,t;
cout << "Input number:" << endl;
cin >> t;
while (t != -1)
{
narry[sum] = t;
addr[sum - 1] = t;
sum++;
cin >> t;
}
sum -= 1;
QSort (narry,1,sum);
for (int i = 1; i <= sum;i++)
cout << narry[i] << '\t';
cout << endl;
intk;
cout << "Please input place you want:" << endl;
cin >> k;
intaa = 1;
intkk = 0;
for (;;)
{
if (aa == k)
break;
if (narry[kk] != narry[kk + 1])
{
aa += 1;
kk++;
}
}
cout << ¡°The NO.¡± << k << ¡°number is:¡± << narry[sum - kk] << endl;
cout << ¡°And it¡¯s place is:¡± ;
for (i = 0;i < sum;i++)
{
if (addr[i] == narry[sum - kk])
cout << i << ¡®\t¡¯;
}


return0;
}


¡¾´ó ÖРС¡¿¡¾´òÓ¡¡¿ ¡¾·±Ìå¡¿¡¾Í¶¸å¡¿¡¾Êղء¿ ¡¾ÍƼö¡¿¡¾¾Ù±¨¡¿¡¾ÆÀÂÛ¡¿ ¡¾¹Ø±Õ¡¿ ¡¾·µ»Ø¶¥²¿¡¿
ÉÏһƪ£ºÊ·ÎÞÇ°ÀýµÄÊý¾Ý½á¹¹Ì⣬ºÜÄÑ! ÏÂһƪ£º¼¼Êõ½»Á÷ÂÛ̳Öп´µ½µÄphpÃæÊÔÌâ

×îÐÂÎÄÕÂ

ÈÈÃÅÎÄÕÂ

Hot ÎÄÕÂ

Python

C ÓïÑÔ

C++»ù´¡

´óÊý¾Ý»ù´¡

linux±à³Ì»ù´¡

C/C++ÃæÊÔÌâÄ¿